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 |
牛人帮帮忙看看WA#include<stdio.h> int main() { int n,j,i,k,m,y,sum,a[1000],count,flag,max,z; scanf("%d\n",&n); for (i=1;i<=n;i++) { sum=0;count=0;flag=0; scanf ("%d %d\n",&z,&k); { for (j=0;j<=k-1;j++) scanf("%d",&a[j]); getchar(); for (j=1;j<=k-1;j++) { for (m=0;m<=j-1;m++) { if (a[j]>a[m]) { max=a[j]; for (y=j-1;y>=m;y--) a[y+1]=a[y]; a[m]=max; } } } while (sum<=z&&count<=k) { sum=sum+a[count++]; if (sum>=z) {printf("Scenario #%d:\n",n);printf("%d\n",count);printf("\n");flag=1;break;} } if (flag==0) {printf("Scenario #%d:\n",n);printf("impossible\n");printf("\n");} for (j=0;j<=k-1;j++) a[j]=0; } } return 0; } 是哪里没有考虑到么~ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator