HDU 1070 (structured sorting)

Source: Internet
Author: User
Milk

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 13639 accepted submission (s): 3328


Problem descriptionignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. there are running 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 (random SIVE ).
2. Ignatius drinks 200 ml milk everyday.
3. If the milk left in the bottle is less than 200 ml, 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 200, you shoshould ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
 
Inputthe 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.
 
Outputfor each test case, You shoshould output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you shoshould 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
MengniuMengniuHintIn 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. 
 
Authorignatius. l difficulty: Sort sorting cannot be handy. Time: 8.8 topic: Rococo mainly examines the second-level sorting of struct, and data of the double type cannot be expressed by equal signs directly. The two are equal, it involves precision issues. The second-level sorting sort code is as follows:
<span style="font-size:14px;">#include<stdio.h>#include<algorithm>using namespace std;struct milk{char log[110];int p;int v;double xjb;}a[110];int cmp(milk x,milk y){if(x.xjb!=y.xjb) return x.xjb<y.xjb;return x.v>y.v;}int main(){int n,i,m;scanf("%d",&n);while(n--){scanf("%d",&m);for(i=0;i<m;i++){scanf("%s%d%d",a[i].log,&a[i].p,&a[i].v);//getchar();if(a[i].v>1200)a[i].xjb=a[i].p*1.0/1200;elsea[i].xjb=a[i].p*1.0/a[i].v;}sort(a,a+m,cmp);for(i=0;i<m;i++){if(a[i].v<200)continue;else{printf("%s\n",a[i].log);break;}}}return 0;}</span>

The qsort code is as follows:
<span style="font-size:14px;">#include<stdio.h>#include<stdlib.h>#include<string.h>struct milk{char log[110];int p;int v;double xjb;}a[110];int cmp(const void *a,const void *b){if((*(milk *)a).xjb>(*(milk *)b).xjb)return  1;else if(((*(milk *)a).xjb<(*(milk *)b).xjb))return -1;elsereturn (((milk *)a)->v)<(((milk *)b)->v);}int main(){int t,i,n;scanf("%d",&t);while(t--){scanf("%d",&n);getchar();for(i=0;i<n;i++){scanf("%s %d %d",a[i].log,&a[i].p,&a[i].v);getchar();if(a[i].v>1200)a[i].xjb=a[i].p*1.0/1200;</span>
<span style="font-size:14px;">                           elsea[i].xjb=a[i].p*1.0/a[i].v;}qsort(a,n,sizeof(a[0]),cmp);for(i=0;i<n;i++){if(a[i].v<200)continue;else{printf("%s\n",a[i].log);break;}}}return 0;}</span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.