标签:des style blog ar io color sp for java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45965 Accepted Submission(s): 15395
此题除了要满足例子以外,还要满足一些条件才能真正算ac: 0 1 1 0 1.000 1 0 0.000 5 4 10000 5 2000 2 100 0 300 0 10400.000 数据类型用double,就这样
1 #include<stdio.h> 2 int j[1010],f[1010]; 3 double a[1010]; 4 void paixu(double a[],int k[],int f[],int n) 5 { 6 int i=0,j=n-1,h=k[0],m=f[0]; 7 double t=a[0]; 8 if(n>1){ 9 while(i<j) 10 { 11 for(;i<j;j--) 12 if(a[j]>t){ 13 a[i]=a[j]; 14 f[i]=f[j]; 15 k[i]=k[j]; 16 i++; 17 break; 18 } 19 for(;i<j;i++) 20 { 21 if(a[i]<t){ 22 a[j]=a[i]; 23 f[j]=f[i]; 24 k[j]=k[i]; 25 j--; 26 break; 27 } 28 } 29 } 30 a[i]=t; 31 f[i]=m; 32 k[i]=h; 33 paixu(a,k,f,i); 34 paixu(a+i+1,k+i+1,f+i+1,n-i-1); 35 } 36 } 37 void hanshu(int m,int n) 38 { 39 int i; 40 double sum=0; 41 for(i=0;i<n;i++) 42 { 43 if(m>=f[i]){ 44 sum=sum+j[i]; 45 m=m-f[i]; 46 } 47 else{ 48 sum=sum+1.0*m/f[i]*j[i]; 49 break; 50 } 51 } 52 printf("%0.3f\n",sum); 53 } 54 int main() 55 { 56 int n,m,i,t; 57 while(1) 58 {scanf("%d%d",&m,&n); 59 if(m==-1&&n==-1)break; 60 for(i=0;i<n;i++) 61 {scanf("%d%d",&j[i],&f[i]); 62 if(f[i]!=0)a[i]=1.0*j[i]/f[i]; 63 else a[i]=1020; 64 } 65 paixu(a,j,f,n); 66 hanshu(m,n); 67 } 68 return 0; 69 70 }
标签:des style blog ar io color sp for java
原文地址:http://www.cnblogs.com/dongq/p/4167921.html