Milk

Milk

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 29   Accepted Submission(s) : 11

Font: Times New Roman | Verdana | Georgia

Font Size:  

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

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


继续sort对结构体的排序,这一题容易忽略的是当每天的牛奶费相等时可以继续用牛奶的总量的大小进行判断。另外在处理剔除体积小于
200毫升的牛奶的信息数值时,用了拷贝信息的方法,形成一个新数组,再用sort对其排序


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Milk
{
char S[150];
int v;
double n;//每天的牛奶费 ,不能为int型 
}st[150];


int cmp(Milk a,Milk b)
{
if(a.n!=b.n)  return a.n<b.n;
return  a.v>b.v;//在牛奶费相等的情况下用牛奶的体积进行判断 



int main()
{
int T,N,i,j;
double p;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(i=0,j=0;i<N;i++)
   {
    scanf("%s",st[i].S);
    scanf("%lf%d",&p,&st[i].v);
   
       if(st[i].v<200)
           continue;
           
       if(st[i].v>1000)
       st[i].n=p/5;
       
       if(st[i].v>=200&&st[i].v<=1000)
    st[i].n=p/(st[i].v/200);
   
    st[j].n=st[i].n;//将牛奶的信息储存,以剔除小于200的牛奶 
    strcpy(st[j].S,st[i].S);
    j++;
   
   }
      sort(st,st+j,cmp);//将剔除了小于200的牛奶之后剩余的部分进行排序 
      printf("%s\n",st[0].S);
    }
return 0;
}

你可能感兴趣的:(Milk)