当前位置:网站首页>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/7/2 question summary
- Bubble sort summary
- 嵌入式数据库开发编程(六)——C API
- [allocation problem] 455 Distribute cookies
- PR first time
- win下一键生成当日的时间戳文件
- Es module and commonjs learning notes -- ESM and CJS used in nodejs
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- cocos_ Lua loads the file generated by bmfont fnt
- Cocos progress bar progresstimer
猜你喜欢
随机推荐
Stm32cubemx (8): RTC and RTC wake-up interrupt
The present is a gift from heaven -- a film review of the journey of the soul
Count sort
SDEI初探-透过事务看本质
Use of snippets in vscode (code template)
Unity writes timetables (without UI)
FVP和Juno平台的Memory Layout介绍
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
The difference between heap and stack
Embedded database development programming (V) -- DQL
Lua GBK and UTF8 turn to each other
被舆论盯上的蔚来,何时再次“起高楼”?
Sixth note
Double pointer Foundation
Do a small pressure test with JMeter tool
Shell Sort
Romance of programmers on Valentine's Day
Heap sort summary
嵌入式数据库开发编程(五)——DQL
Kali 2018 full image download