当前位置:网站首页>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;
}
边栏推荐
- 2022年上半年国家教师资格证考试
- Web APIs DOM节点
- Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
- Under the national teacher qualification certificate in the first half of 2022
- 2022/7/2做题总结
- Bucket sort
- Unity intelligent NPC production -- pre judgment walking (method 1)
- Judge the position of the monster in the role under unity3d
- Research on the value of background repeat of background tiling
- 2021-10-29
猜你喜欢
BUUCTF MISC
win10虚拟机集群优化方案
嵌入式数据库开发编程(零)
2022/7/2做题总结
Collapse of adjacent vertical outer margins
JVM call not used once in ten years
[转]MySQL操作实战(一):关键字 & 函数
[turn to] MySQL operation practice (I): Keywords & functions
远程升级怕截胡?详解FOTA安全升级
Django reports an error when connecting to the database. What is the reason
随机推荐
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
PR first time
[LeetCode] 整数反转【7】
Programmers' experience of delivering takeout
stm32Cubemx(8):RTC和RTC唤醒中断
Redis has four methods for checking big keys, which are necessary for optimization
Grail layout and double wing layout
Download xftp7 and xshell7 (official website)
JVM call not used once in ten years
2022/7/2做题总结
质量体系建设之路的分分合合
Unity writes timetables (without UI)
Bucket sort
Solon 框架如何方便获取每个请求的响应时间?
Leetcode word search (backtracking method)
【ES实战】ES上的native realm安全方式使用
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
[speed pointer] 142 circular linked list II
A three-dimensional button
Chinese notes of unit particle system particle effect