标签:
给每种牛奶价格和量
要求买最便宜的牛奶
1 #include <iostream> 2 using namespace std; 3 int t,n; 4 char name[105][105]; 5 int cost[105],v[105]; 6 int main() 7 { 8 int i,ans,len; 9 double minn,ave; 10 scanf("%d",&t); 11 while(t--) 12 { 13 scanf("%d",&n); 14 minn=1e9; 15 ans=0; 16 for(i=1;i<=n;i++) 17 { 18 scanf("%s%d%d",name[i],&cost[i],&v[i]); 19 if(v[i]<200) continue; 20 len=min(5,v[i]/200); 21 ave=1.0*cost[i]/len; 22 if(ave<minn) 23 { 24 minn=ave; 25 ans=i; 26 } 27 else if(ave-minn<=0.0001&&minn-ave>=-0.0001)//相等的时候挑多的? 28 { 29 if(v[i]>v[ans]) 30 { 31 minn=ave; 32 ans=i; 33 } 34 } 35 } 36 printf("%s\n",name[ans]); 37 } 38 }
标签:
原文地址:http://www.cnblogs.com/nicetomeetu/p/5516006.html