Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13639 Accepted Submission(s): 3328
2 2 Yili 10 500 Mengniu 20 1000 4 Yili 10 500 Mengniu 20 1000 Guangming 1 199 Yanpai 40 10000
Mengniu MengniuHintIn 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.
<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; else a[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>
<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; else return (((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;"> else a[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>
hdu 1070(结构体排序),布布扣,bubuko.com
原文地址:http://blog.csdn.net/ice_alone/article/details/38435493