简单题
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct node 4 { 5 double dan,weight; 6 }a[1005]; 7 bool cmp(node x,node y) 8 { 9 return x.dan<y.dan; 10 } 11 void init() 12 { 13 for(int i=0;i<1005;i++) 14 { 15 a[i].dan=0.0;a[i].weight=0.0; 16 } 17 } 18 int main() 19 { 20 int c; 21 while(~scanf("%d",&c)) 22 { 23 while(c--) 24 { 25 double n;int m; 26 scanf("%lf %d",&n,&m); 27 init(); 28 for(int i=0;i<m;i++) 29 { 30 scanf("%lf %lf",&a[i].dan,&a[i].weight); 31 } 32 sort(a,a+m,cmp);double ans=0; 33 for(int i=0;i<m;i++) 34 { 35 if(n>0) 36 { 37 if(n>=a[i].dan*a[i].weight) 38 { 39 n-=a[i].dan*a[i].weight; 40 ans=a[i].weight+ans; 41 } 42 else 43 { 44 ans=n/a[i].dan+ans; 45 n=0;break; 46 } 47 } 48 } 49 printf("%.2lf ",ans); 50 } 51 } 52 return 0; 53 }