当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

用 Jmeter 工具做个小型压力测试

Quick sort summary

十年不用一次的JVM调用
![[转]MySQL操作实战(一):关键字 & 函数](/img/b1/8b843014f365b786e310718f669043.png)
[转]MySQL操作实战(一):关键字 & 函数

Unity ugui source code graphic

C4D simple cloth (version above R21)

Generate filled text and pictures

The present is a gift from heaven -- a film review of the journey of the soul

TF-A中的工具介绍

Optimization scheme of win10 virtual machine cluster
随机推荐
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
LeetCode之單詞搜索(回溯法求解)
一个新的微型ORM开源框架
[allocation problem] 135 Distribute candy
Unity writes timetables (without UI)
Development error notes
[LeetCode] 整数反转【7】
room数据库的使用
Magnifying glass effect
C language Essay 1
Leetcode word search (backtracking method)
嵌入式数据库开发编程(零)
Solon Logging 插件的添加器级别控制和日志器的级别控制
《动手学深度学习》学习笔记
Reverse one-way linked list of interview questions
Unity card flipping effect
The present is a gift from heaven -- a film review of the journey of the soul
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
cocos_ Lua listview loads too much data
Data is stored in the form of table