当前位置:网站首页>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;
}
边栏推荐
- Pause and resume of cocos2dx Lua scenario
- Unity sends messages and blocks indecent words
- Research on the value of background repeat of background tiling
- Solon Logging 插件的添加器级别控制和日志器的级别控制
- Heap sort summary
- Solon Auth 认证框架使用演示(更简单的认证框架)
- Unity get component
- 远程升级怕截胡?详解FOTA安全升级
- [leetcode] integer inversion [7]
- TF-A中的工具介绍
猜你喜欢
Leetcode word search (backtracking method)
Django reports an error when connecting to the database. What is the reason
Double pointer Foundation
小程序直播+电商,想做新零售电商就用它吧!
支持多模多态 GBase 8c数据库持续创新重磅升级
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Fragment addition failed error lookup
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Reverse one-way linked list of interview questions
Magnifying glass effect
随机推荐
PR first time
Unity writes timetables (without UI)
C4D simple cloth (version above R21)
JVM call not used once in ten years
Lua determines whether the current time is the time of the day
Magnifying glass effect
UE fantasy engine, project structure
UE 虚幻引擎,项目结构
[speed pointer] 142 circular linked list II
Development error notes
被舆论盯上的蔚来,何时再次“起高楼”?
[turn to] MySQL operation practice (III): table connection
cocos_ Lua loads the file generated by bmfont fnt
This article is good
Embedded database development programming (V) -- DQL
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
2022/7/1 learning summary
Unity find the coordinates of a point on the circle
Optimization scheme of win10 virtual machine cluster
Lua GBK and UTF8 turn to each other