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 |
牛人们救救我!怎么老是输出1!(附原代码)#include<stdio.h> #include<stdlib.h> int main() { int a[1002]; int n,i,j,need,sum,b,q,zb,flag; scanf("%d",&n); for(i=0;i<n;i++) { sum=0;q=0;flag=0;zb=1;b=0; scanf("%d%d",&need,&a[0]); for(j=1;j<=a[0];j++)scanf("%d",&a[j]); for(j=1;j<=a[0];j++) {for(j=1;j<=a[0];j++) if(b<=a[j]){b=a[j];zb=j;} a[zb]=0; sum+=b; q++; /**/if(sum>need){printf("Scenario #%d:\n%d\n\n",i+1,q);flag=1;break;} } if(flag==0) printf("Scenario #%d:\nimpossible\n\n",i+1); } system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator