题目链接:https://www.patest.cn/contests/gplt/L2-003
现在只能做水题~
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 const int maxn = 1e3+5; 7 struct _node_ 8 { 9 double save; 10 double saleprice; 11 double costperformance; 12 }; 13 _node_ node[maxn]; 14 bool cmp(_node_ A,_node_ B) 15 { 16 return A.costperformance>B.costperformance; 17 } 18 int main() 19 { 20 int n; 21 double maxneed; 22 cin>>n>>maxneed; 23 for(int i=0;i<n;i++) 24 { 25 cin>>node[i].save; 26 } 27 for(int i=0;i<n;i++) 28 { 29 cin>>node[i].saleprice; 30 } 31 for(int i=0;i<n;i++) 32 { 33 node[i].costperformance = node[i].saleprice/node[i].save; 34 } 35 sort(node,node+n,cmp); 36 double sum = 0; 37 for(int i=0;i<n;i++) 38 { 39 if(node[i].save<maxneed) 40 { 41 sum += node[i].saleprice; 42 maxneed -= node[i].save; 43 } 44 else if(node[i].save>=maxneed) 45 { 46 sum += node[i].costperformance*maxneed; 47 break; 48 } 49 } 50 printf("%.2f ",sum); 51 return 0; 52 }