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 |
helpIn Reply To:help Posted by:mark1553 at 2005-08-22 16:17:15 #include <stdio.h> main() { int t,i,j,p, k,n=0,m=0,a[101]; scanf("%d",&t); for(i=0;i<t;i++)scanf("%d",&a[i]); if(t==1){n=a[0];m=0;} if(t>1) {for(i=0;i<t-1;i++) for(j=i+1;j<t;j++) if(a[i]>a[j]){k=a[j];a[j]=a[i];a[i]=k;} n=n+a[i]; m=m+a[i-1]; j=0; for(p=i-2;p>=0;p--) {if(n>m){m+=a[p] ; if(p>j&&n>m){n=n+a[j];j++;if(j==p)break;} if(p>j&&n<m)n=n+a[--p]; } else {n+=a[p];if(p>j&&n<m){m=m+a[j];j++;if(j==p)break; }} if(j==p)break; } } if(n<m){k=m;m=n;n=k;} printf("%d %d\n",m,n); } 打死我都不知道哪里错了! 自己测了N次 都对 一叫就WRONG Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator