标签:des style blog http color os io java strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20968 Accepted Submission(s): 6501
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 struct WareHouse 6 { 7 int JB,CF; 8 double ratio; 9 }; 10 bool cmp(WareHouse a,WareHouse b) 11 { 12 return a.ratio > b.ratio; 13 } 14 int main() 15 { 16 int m,n; 17 while(scanf_s("%d%d",&m,&n)&&m!=-1&&n!=-1) 18 { 19 double answer=0; 20 //int*p = new int[n]; 21 vector<WareHouse> WH; 22 int i=n; 23 while(i--) 24 { 25 WareHouse temp; 26 scanf_s("%d%d",&temp.JB,&temp.CF); 27 temp.ratio = (double)temp.JB/temp.CF; 28 WH.push_back(temp); 29 } 30 // sort(WH.begin(),WH.end(),[](const WareHouse &a,const WareHouse&b ){ return a.ratio>b.ratio;}); 31 sort(WH.begin(),WH.end(),cmp); 32 for (int j = 0; j < n; j++) 33 { 34 if(m<=WH[j].CF) 35 { 36 answer=answer+m*WH[j].ratio; 37 m=0; 38 } 39 else 40 { 41 answer=answer+WH[j].JB; 42 m-=WH[j].CF; 43 } 44 } 45 printf("%.3f\n",answer); 46 } 47 return 0; 48 }
标签:des style blog http color os io java strong
原文地址:http://www.cnblogs.com/makeitsure/p/3950144.html