http://acm.hdu.edu.cn/showproblem.php?pid=1070
Milk
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13526 Accepted Submission(s): 3296
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.
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.
2 2 Yili 10 500 Mengniu 20 1000 4 Yili 10 500 Mengniu 20 1000 Guangming 1 199 Yanpai 40 10000
Mengniu Mengniu#include<stdio.h> struct Things { char S[200]; double P;//单价要用double型,以为算每日消费时可能得到小数,不能只取整 int V; }thing[200]; int main() { int T,N,i,j,k; double M; scanf("%d",&T); while(T--) { scanf("%d",&N); for(i=0,j=0;i<N;i++) { scanf("%s %d %d",thing[j].S,&thing[j].P,&thing[j].V); if(thing[j].V>=200) j+=1; } //printf("%d#\n",j); for(i=1,k=0,M=thing[0].P/(thing[0].V/200);i<j;i++) { if(thing[i].V/200<=5) { if(M>thing[i].P/(thing[i].V/200)) { M=thing[i].P/(thing[i].V/200); k=i; } if(M==thing[i].P/(thing[i].V/200)&&thing[i].V>thing[k].V) { k=i; } } else if(thing[i].V/200>5) { if(M>thing[i].P/5) { M=thing[i].P/5; k=i; } } } printf("%s\n",thing[k].S); } return 0; }
186



被折叠的 条评论
为什么被折叠?



