HDU-1070-Milk
来源:互联网 发布:手机怎么删除淘宝地址 编辑:程序博客网 时间:2024/05/28 16:17
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070
Milk
Problem Description
Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. There are many kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest.
Here are some rules:
1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive).
2. Ignatius drinks 200mL milk everyday.
3. If the milk left in the bottle is less than 200mL, Ignatius will throw it away.
4. All the milk in the supermarket is just produced today.
Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
Here are some rules:
1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive).
2. Ignatius drinks 200mL milk everyday.
3. If the milk left in the bottle is less than 200mL, Ignatius will throw it away.
4. All the milk in the supermarket is just produced today.
Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
Output
For each test case, you should output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you should output the one which has the largest volume.
Sample Input
22Yili 10 500Mengniu 20 10004Yili 10 500Mengniu 20 1000Guangming 1 199Yanpai 40 10000
Sample Output
MengniuMengniuHintIn the first case, milk Yili can be drunk for 2 days, it costs 10 Yuan. Milk Mengniu can be drunk for 5 days, it costs 20 Yuan. So Mengniu is the cheapest.In the second case,milk Guangming should be ignored. Milk Yanpai can be drunk for 5 days, but it costs 40 Yuan. So Mengniu is the cheapest.
喝牛奶的条件:1.喝同一瓶牛奶不能超过5天。2.不喝200ml以下的牛奶。3.求出最便宜的牛奶且容量最多。注意平均价格=价格/天数,结构体排序,根据价格排序,再根据体积排序,体积小于200的可以令他的价格为无限大。
代码如下:
#include<iostream>#include<algorithm>#include<cstring>using namespace std;struct milk{ char name[111]; double price; int volume; double cost;};bool cmp(milk x,milk y){ if(x.cost==y.cost)return x.volume>y.volume; return x.cost<y.cost;}int main(){ int T,m,i,j,k; cin>>T; while(T--) { cin>>m; milk st[111]; for(i=1;i<=m;i++) { cin>>st[i].name>>st[i].price>>st[i].volume; if(st[i].volume<200) st[i].cost=9999999; else if(st[i].volume<=1200)//喝5天的范围内 st[i].cost=st[i].price*1.0/(st[i].volume*1.0/200); else st[i].cost=st[i].price*1.0/(1200*1.0/200); } sort(st+1,st+1+m,cmp); cout<<st[1].name<<endl; } return 0;}
阅读全文
0 0
- hdu 1070 Milk(水)
- 水题 hdu 1070 milk
- HDU 1070 Milk
- hdu 1070 Milk
- hdu 1070 milk
- Milk hdu 1070
- hdu 1070 Milk
- hdu 1070 Milk
- hdu 1070 Milk
- HDU 1070 Milk
- hdu 1070 Milk
- Milk hdu 1070
- hdu 1070 Milk
- hdu 1070 Milk
- hdu-oj 1070 Milk
- HDU 1070 Milk
- hdu 1070 milk
- HDU 1070 Milk
- Callable使用示例
- 【总结】错误解析和字符集
- HDU6030 Happy Necklace[矩阵快速幂]
- CSU月赛1974
- 运放 采集电压 电流高端采样
- HDU-1070-Milk
- [LeetCode] 394. Decode String
- CopyOnWriteArrayList使用示例
- POJ 1704 Georgia and Bob
- [leetcode]652. Find Duplicate Subtrees
- 2017 中国电信(美洲)公司CTExcel电话卡使用攻略
- 写高质量OC代码52建议总结:52.NSTimer会保留其目标对象
- JS
- CountDownLatch使用示例