Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
兄弟,先从大到小排序再求和就行了In Reply To:牛人们;帮我查一下错误(附源码)这么简单的题你们看一眼就OK!!! Posted by:aaasssaaasss at 2005-08-07 09:46:26 > #include<stdio.h> > int main() > { > int i,j,t; > int n,m,p=0; > int a[1000],b[1000]; > long k,sum; > scanf("%d",&n); > while(p<n) > { > sum=0; > scanf("%ld%d",&k,&m); > for(i=0;i<m;i++) > scanf("%d",&a[i]); > > for(i=0;i<m-1;i++) > { > for(j=m-1;j>=i;j--) > { > if(a[j]<a[j+1]) > { > t=a[j+1];a[j+1]=a[j];a[j]=t; > } > } > sum+=a[i]; > if(sum<k) > b[p]=i+2; > } > if(sum<k) > b[p]=0; > p++; > } > for(i=0;i<n;i++) > { > printf("Scenario #%d:\n",i+1); > if(b[i]==0) > printf("impossible\n"); > if(b[i]!=0) > printf("%d\n",b[i]); > printf("\n"); > } > return 1; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator