当前位置:网站首页>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;
}
边栏推荐
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- Ue4/ue5 illusory engine, material part (III), material optimization at different distances
- 嵌入式数据库开发编程(零)
- 2022/7/1 learning summary
- [interval problem] 435 Non overlapping interval
- Kali 2018 full image download
- Transport connection management of TCP
- 【ES实战】ES上的native realm安全方式使用
- Unity enables mobile phone vibration
- [turn to] MySQL operation practice (I): Keywords & functions
猜你喜欢
![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[轉]: OSGI規範 深入淺出

支持多模多态 GBase 8c数据库持续创新重磅升级

Panel panel of UI

Research on the value of background repeat of background tiling

Romance of programmers on Valentine's Day

Redis has four methods for checking big keys, which are necessary for optimization

十年不用一次的JVM调用

Leetcode word search (backtracking method)

小程序直播+電商,想做新零售電商就用它吧!

To the distance we have been looking for -- film review of "flying house journey"
随机推荐
BUUCTF MISC
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Solon Logging 插件的添加器级别控制和日志器的级别控制
[merge array] 88 merge two ordered arrays
Merge sort
Cocos2dx screen adaptation
2022上半年全国教师资格证下
Download and use of font icons
PMP考生,请查收7月PMP考试注意事项
Unity shot tracking object
django连接数据库报错,这是什么原因
National teacher qualification examination in the first half of 2022
[binary search] 34 Find the first and last positions of elements in a sorted array
C iterator
[speed pointer] 142 circular linked list II
Generate filled text and pictures
The present is a gift from heaven -- a film review of the journey of the soul
The difference between heap and stack
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
Data is stored in the form of table