|
|
вернуться в форумhelp me test 5 Послано Igor 14 сен 2005 23:45 #include <iostream> using namespace std; long long a,n,w[25],c,s,b; int main() { cin >>n; a=1; w[0]=0; for ( ;a<=n;a++) cin >>w[a]; a=1; if (n==1) cout <<w[1]<<"\n"; else { for ( ;a<=n;a++) { s=a; for ( s;s<=n-1;s++) { if (w[a]>w[s+1]) { c=w[a]; w[a]=w[s+1]; w[s+1]=c;}; } } a=n; for ( ;a>=3;a--) { w[a-1]=w[a]-w[a-1]; if (w[a-2]>w[a-1]) {c=w[a-2]; w[a-2]=w[a-1]; w[a-1]=c;}; } cout <<w[2]-w[1]<<"\n"; } return 0; } Re: help me test 5 You solve is very big. My solve get WA5, but my solve if less. on C: #include <stdio.h> void main() { int n,i,j; __int64 w[21],s1=0,s2=0; scanf("%d",&n); for(i=0;i<n;++i)scanf("%I64d",&w[i]); for(i=0;i<n-1;++i)for(j=i+1;j<n;++j) if(w[i]<w[j]){int t=w[i];w[i]=w[j]; w[j]=t;}; s1=w[0]; for(i=1;i<n;++i) if(s1<s2)s1+=w[i]; else s2+=w[i]; if(s1>s2)s1-=s2; else s1=s2-s1; printf("%I64d",s1); } Re: help me test 5 Both solution is wrang. Try full search. |
|
|