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 |
郁闷了,c++提交OLE, G++提交 WA,到底是哪里大问题,各位帮我看看到底是哪里的问题In Reply To:输出序最小的好了,就不写spj了 Posted by:hawk at 2005-07-06 12:41:46 #include <stdio.h> #include <algorithm>// _int64 long long _int64 n,i,j,k,ns,sum[37],tmp,len,a[10]; bool b[37],Im; int main() { b[0] = b[1] = true; while(scanf("%I64d",&n)!= EOF) { ns = n*(n-1)/2; for(i=0; i<ns; i++) { scanf("%I64d",&sum[i]); b[i] = false; } std::sort(sum,sum+ns); Im = true; for(i=2; i<ns; i++) { a[2] = (sum[1] - sum[0] + sum[i])/2; a[1] = sum[i] - a[2]; a[0] = sum[0] - a[1]; if(a[2]*2 != sum[1] - sum[0] + sum[i]) continue; len = 3; b[i] = true; for(j=2; j<ns; j++) { if(!b[j]) { a[len++] = sum[j] - a[0]; b[j] = true; tmp = 1; for(k=j+1; k<ns&&tmp<len-1; k++) { if(!b[k]&&(a[tmp]+a[len-1] == sum[k])) { b[k]=true; tmp++; } } } } if(len==n) { Im = false; break; } for(k=2; k<ns; k++) b[k] = false; } if(Im) printf("Impossible\n"); else { for(k=0; k<len-1; k++) printf("%I64d ",a[k]); printf("%I64d\n",a[len-1]); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator