当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
UE 虚幻引擎,项目结构
用 Jmeter 工具做个小型压力测试
[turn to] MySQL operation practice (III): table connection
BUUCTF MISC
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
Redis has four methods for checking big keys, which are necessary for optimization
小程序直播+電商,想做新零售電商就用它吧!
Romance of programmers on Valentine's Day
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Fragment addition failed error lookup
随机推荐
Unity synergy
django连接数据库报错,这是什么原因
[转]: OSGI规范 深入浅出
Web APIs DOM节点
Solon 框架如何方便获取每个请求的响应时间?
Listview is added and deleted at the index
Sixth note
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Learning notes of "hands on learning in depth"
Transport connection management of TCP
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
win10虚拟机集群优化方案
TF-A中的工具介绍
一个新的微型ORM开源框架
2022/7/2做题总结
Unity writes timetables (without UI)
Collapse of adjacent vertical outer margins
C language Essay 1
PMP考生,请查收7月PMP考试注意事项
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!