标签:des style blog http io color sp for 数据
Sample Input
1 #include <stdio.h> 2 3 int main(){ 4 int T; 5 int n; 6 int m; 7 int i; 8 int j; 9 int price[1001]; 10 int volume[1001]; 11 int temp; 12 double totalAmount; 13 double amount; 14 15 scanf("%d",&T); 16 17 while(T--){ 18 scanf("%d%d",&n,&m); 19 20 for(i=0;i<m;i++){ 21 scanf("%d%d",&price[i],&volume[i]); 22 } 23 24 for(i=0;i<m-1;i++){ 25 for(j=i+1;j<m;j++){ 26 if(price[i]>price[j]){ 27 temp=price[i]; 28 price[i]=price[j]; 29 price[j]=temp; 30 31 temp=volume[i]; 32 volume[i]=volume[j]; 33 volume[j]=temp; 34 } 35 } 36 } 37 38 totalAmount=0; 39 for(i=0;i<m;i++){ 40 amount=(double)n/price[i]; 41 if(amount>volume[i]){ 42 n-=price[i]*volume[i]; 43 totalAmount+=volume[i]; 44 } 45 else{ 46 totalAmount+=amount; 47 break; 48 } 49 } 50 51 printf("%.2lf\n",totalAmount); 52 } 53 return 0; 54 }
标签:des style blog http io color sp for 数据
原文地址:http://www.cnblogs.com/zqxLonely/p/4088542.html