当前位置:网站首页>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;
}
边栏推荐
- cocos_ Lua loads the file generated by bmfont fnt
- [speed pointer] 142 circular linked list II
- Solon 框架如何方便获取每个请求的响应时间?
- [turn to] MySQL operation practice (I): Keywords & functions
- 2022/7/1學習總結
- BUUCTF MISC
- Basic knowledge points of dictionary
- Optimization scheme of win10 virtual machine cluster
- xftp7与xshell7下载(官网)
- Unity find the coordinates of a point on the circle
猜你喜欢

Use of snippets in vscode (code template)

2021-10-29
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
[merge array] 88 merge two ordered arrays

Download and use of font icons

GBase数据库助力湾区数字金融发展

The present is a gift from heaven -- a film review of the journey of the soul

Generate filled text and pictures

To the distance we have been looking for -- film review of "flying house journey"

Merge sort

对象的序列化
随机推荐
Listview is added and deleted at the index
被舆论盯上的蔚来,何时再次“起高楼”?
2022/7/1學習總結
Research on the value of background repeat of background tiling
Embedded database development programming (zero)
Cocos create Jiugongge pictures
Do a small pressure test with JMeter tool
[to be continued] [UE4 notes] L1 create and configure items
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
《动手学深度学习》学习笔记
Download and use of font icons
[interval problem] 435 Non overlapping interval
Magnifying glass effect
质量体系建设之路的分分合合
2022年上半年国家教师资格证考试
Unity writes timetables (without UI)
嵌入式数据库开发编程(五)——DQL
[转]MySQL操作实战(一):关键字 & 函数
LeetCode之單詞搜索(回溯法求解)
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存