标签:hid 技术 scanf item image block one pen space
这题用结构体排序外加一点贪心的思想比较好。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #define max 110 6 using namespace std; 7 struct milk{ 8 char name[max]; 9 //int price; 10 int v; 11 int day; 12 double rate; 13 }item[max]; 14 bool cmp(milk a, milk b) 15 { 16 if(a.rate < b.rate){ 17 return true; 18 }else if(a.rate == b.rate){ 19 if(a.v>b.v){ 20 return true; 21 }else{ 22 return false; 23 } 24 }else{ 25 return false; 26 } 27 28 } 29 30 int main() 31 { 32 //freopen("in.txt","r",stdin); 33 char tname[max]; 34 int tprice; 35 int tv; 36 int t,n; 37 scanf("%d",&t); 38 while(t--){ 39 scanf("%d",&n); 40 int i; 41 for(i = 0;i<n;i++){ 42 scanf("%s %d %d",tname,&tprice,&tv); 43 //item[i].price = tprice; 44 if(tv<200){ 45 n--; 46 i--; 47 continue; 48 }else if(tv>=1000){ 49 strcpy(item[i].name,tname); 50 item[i].v = tv; 51 item[i].day = 5; 52 item[i].rate = 1.0 * tprice / 5; 53 // break; 54 }else { 55 strcpy(item[i].name,tname); 56 item[i].v = tv; 57 item[i].day = tv / 200; 58 item[i].rate = 1.0 * tprice / item[i].day; 59 // break; 60 } 61 62 //} 63 } 64 sort(item,item+n,cmp); 65 printf("%s\n",item[0].name); 66 67 68 } 69 return 0; 70 }
标签:hid 技术 scanf item image block one pen space
原文地址:http://www.cnblogs.com/ACDoge/p/6130363.html