HDU-1070 Milk 结构体排序
来源:互联网 发布:独立ip linux虚拟主机 编辑:程序博客网 时间:2024/05/19 18:45
Milk
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.
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.
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
2
2
Yili 10 500
Mengniu 20 1000
4
Yili 10 500
Mengniu 20 1000
Guangming 1 199
Yanpai 40 10000
Sample Output
Mengniu
Mengniu
Hint
In 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.
此题的思想是结构体数组排序,坑点在当单位花费相同时的比较,若单位花费相同,则选择多的
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;struct p{ char bound[101]; int day; double value; double v; double rate;}milk[110];bool operator < (const p&a,const p&b){if(a.rate!=b.rate) return a.rate<b.rate; else return a.v>b.v;//若rate相同,则选多的}int main(){ int n,t; cin>>t; while(t--){ while(~scanf("%d",&n)&&n) { for(int i=0;i<n;i++) { cin>>milk[i].bound; cin>>milk[i].value; cin>>milk[i].v; milk[i].day=milk[i].v/200; if(milk[i].day>=5) milk[i].day=5; milk[i].rate=(double)(milk[i].value*1.0/(double)milk[i].day); }sort(milk,milk+n);cout<<milk[0].bound<<endl; }}}
- HDU-1070 Milk 结构体排序
- usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)
- hd 1070 Milk(sort+结构体)
- Milk(sort+结构体) hd 1070
- 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 1070 Milk
- HDU 1070 Milk
- hdu 1070 Milk
- Milk hdu 1070
- 进制的转换 有问题版本
- bzoj2142 礼物 ( 扩展Lucas )
- 思考
- HDU 5938 Four Operations(思维)
- 剑指offer:变态跳台阶
- HDU-1070 Milk 结构体排序
- C语言 55555图形 找车牌问题
- 实验二木马分析(控制分析)实验和实验三冰河木马实验
- VB6.0中“command”控件的default属性是不是失效了
- 对象方法练习
- MySQL之生成唯一的序列号和删除重复数据
- 守护进程
- AssetBundle系统整理(二)_实用技巧
- 【树剖】【树上差分】部落冲突