标签:bit sort nbsp printf 提示 提交 its 提问 pac
2 50 4 10 100 50 30 7 34 87 100 10000 5 1 43 43 323 35 45 43 54 87 43
171.93 508.00
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 struct Node{ 5 double n,v; 6 double q; 7 }a[105]; 8 bool cmp(Node a,Node b){ 9 return a.q>b.q; 10 } 11 int main() { 12 int k,s,w; 13 cin>>k; 14 while(k--){ 15 cin>>w>>s; 16 for(int i=0;i<s;i++){ 17 cin>>a[i].n>>a[i].v; 18 a[i].q=a[i].v/a[i].n; 19 } 20 double ans=0; 21 sort(a,a+s,cmp); 22 int i=0; 23 while(w>0){ 24 if(w-a[i].n>0){ 25 ans+=a[i].v; 26 w-=a[i].n; 27 i++; 28 } 29 else { 30 ans+=a[i].q*w; 31 w=0; 32 } 33 } 34 printf("%.2lf\n",ans); 35 36 37 } 38 39 return 0; 40 }
标签:bit sort nbsp printf 提示 提交 its 提问 pac
原文地址:https://www.cnblogs.com/aiqinger/p/12587797.html