当前位置:网站首页>Haut OJ 1350: choice sends candy
Haut OJ 1350: choice sends candy
2022-07-05 05:17:00 【hunziHang】
Problem description :
Christmas is coming ,Choice Prepare to send some candy as a gift , Yes n Grow candy , Each kind of candy has mi individual , The price of candy is pi(pi yes mi The total price of candies ), Each kind of candy can be broken into any one to take away , however Choice At most w A candy , Of course Choice Not a stingy person , She takes expensive candy as much as possible , Excuse me, Choice What value candy can you take away at most ?
Cause analysis :
for Inside i ,sort Inside n Can't be decimal , It can't be defined as double etc.
Solution :
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef struct tg{
double tp,num,p;
}T;
bool cmp(T a,T b)
{
return a.p>b.p;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
double w;
while(cin>>n>>w)
{
T a[1005];
int i,j;
double sum=0,count;
for(i=0;i<n;i++)
{
cin>>a[i].tp>>a[i].num;
a[i].p=a[i].tp/a[i].num;
}
sort(a,a+n,cmp);
for(i=0;i<n;i++)
{
if(w>0)
{
count=min(a[i].num,w);
sum+=a[i].p*count;
w-=count;
}
else
break;
}
cout<<fixed<<setprecision(1)<<sum<<endl;
}
return 0;
}
边栏推荐
- Under the national teacher qualification certificate in the first half of 2022
- Solon 框架如何方便获取每个请求的响应时间?
- 嵌入式数据库开发编程(零)
- [leetcode] integer inversion [7]
- 【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
- Research on the value of background repeat of background tiling
- Romance of programmers on Valentine's Day
- Panel panel of UI
- Generate filled text and pictures
- xftp7与xshell7下载(官网)
猜你喜欢
随机推荐
Simple modal box
Unity3d learning notes
PR first time
[trans]: spécification osgi
64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
Es module and commonjs learning notes
Cocos2dx screen adaptation
[to be continued] [UE4 notes] L1 create and configure items
The present is a gift from heaven -- a film review of the journey of the soul
stm32Cubemx(8):RTC和RTC唤醒中断
Unity and database
Heap sort summary
[转]MySQL操作实战(一):关键字 & 函数
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Lua GBK and UTF8 turn to each other
Magnifying glass effect
小程序直播+電商,想做新零售電商就用它吧!
Out and ref functions of unity
十年不用一次的JVM调用








![[转]: OSGI规范 深入浅出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)