当前位置:网站首页>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;
}
边栏推荐
- Bubble sort summary
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- The difference between heap and stack
- Unity synergy
- Learning notes of "hands on learning in depth"
- Generate filled text and pictures
- Cocos2dx screen adaptation
- Double pointer Foundation
- Embedded database development programming (zero)
- 用 Jmeter 工具做个小型压力测试
猜你喜欢
stm32Cubemx(8):RTC和RTC唤醒中断
[转]MySQL操作实战(一):关键字 & 函数
Reverse one-way linked list of interview questions
Do a small pressure test with JMeter tool
Learning notes of "hands on learning in depth"
Heap sort summary
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
win10虚拟机集群优化方案
Unity find the coordinates of a point on the circle
[turn]: OSGi specification in simple terms
随机推荐
一个新的微型ORM开源框架
C4D simple cloth (version above R21)
Use of snippets in vscode (code template)
[轉]: OSGI規範 深入淺出
Research on the value of background repeat of background tiling
Download xftp7 and xshell7 (official website)
Listview is added and deleted at the index
《动手学深度学习》学习笔记
Cocos2dx screen adaptation
[binary search] 34 Find the first and last positions of elements in a sorted array
C语言杂谈1
用 Jmeter 工具做个小型压力测试
When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
Embedded database development programming (zero)
cocos_ Lua loads the file generated by bmfont fnt
【ES实战】ES上的native realm安全方式使用
Kali 2018 full image download
GBase数据库助力湾区数字金融发展
Unity sends messages and blocks indecent words