HDU 1070 Milk

来源:互联网 发布:普通增值税发票软件 编辑:程序博客网 时间:2024/06/06 10:39
  
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.
题意:有个人要去买牛奶,求最便宜的牛奶的名字。
此人的要求:每天只喝200ml。如果瓶子里不足200ml,他就会任何扔掉,而且他不喝6天以后的,(此处意思为只能保存5天。感觉这里题上说的有问题,);
如果存在价钱相同的,就取容量多的为优。这道题简直伤了我的智商,想了 好久才明白,如果大于1000ml。一定不要把容量改为1000ml。因为如果存在一种情况:同为1000ml以上,但是不相同,而且价值相同,我弱弱问一下,改了之后怎么取??答案是取不了。这道题存在精度问题,一定要仔细处理细节问题,这道题我想了好几种方式去ac可只有这一个ac了,,,真心伤了。。
#include<stdio.h>struct node{    char brand[101];    int price;    int v;    int day;    double f;};int main(){    int T;    scanf("%d",&T);    while(T--)    {        struct node t[1000];        int i,n;        scanf("%d",&n);        for(i=0;i<n;i++)        {            scanf("%s%d%d",t[i].brand,&t[i].price,&t[i].v);            t[i].day=t[i].v/200;            if(t[i].day>5)            {                t[i].day=5;            }            t[i].f=t[i].price*1.0/t[i].day;        }        int j=0;          double min=t[0].f;  double max=t[0].v;          for(i=1;i<n;i++)          if(min>t[i].f)              如果平均每天的消费小于t【i】;则更新。        {              min=t[i].f;              j=i;          }          else if(min==t[i].f&&max<t[i].v)    如果相等,则比较容量,        {              j=i;max=t[i].v;          }            printf("%s\n",t[j].brand);   //输出的是牛奶的名字、    }    return 0;}
0 0