hdoj.1070 Milk 20140807

来源:互联网 发布:js formdata 取属性值 编辑:程序博客网 时间:2024/05/19 04:29

Milk

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13555    Accepted Submission(s): 3309


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.
 

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
22Yili 10 500Mengniu 20 10004Yili 10 500Mengniu 20 1000Guangming 1 199Yanpai 40 10000
 

Sample Output
MengniuMengniu
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<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct nn{    char name[110];    double price;      int ml; };int cmp(nn x,nn y){    int day1,day2;    double price1,price2;    day1=x.ml>=1000?5:x.ml/200;    day2=y.ml>=1000?5:y.ml/200;    price1=x.price/day1;    price2=y.price/day2;    if(price1==price2)        return x.ml>y.ml;    return price1<price2;}nn niunai[110];int main(){    int T,n,i;    while(scanf("%d",&T)!=EOF)    {        while(T--)        {            scanf("%d",&n);            getchar();            for(i=0;i<n;i++)            {                scanf("%s %lf %d",niunai[i].name,&niunai[i].price,&niunai[i].ml);                getchar();                if(niunai[i].ml<200)                {                    i--;n--;                }            }            sort(niunai,niunai+n,cmp);            printf("%s\n",niunai[0].name);        }    }    return 0;}

0 0