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 |
Re:错得这么离谱也可以In Reply To:Re:CODE Posted by:T3 at 2005-08-17 00:09:37 > #include <iostream.h> > #include <stdlib.h> > #define AS(x) ((x)<0?-(x):(x)) > void in(int n,int a[],int& s) > { > for(int i=s=0;i<n;++i) > cin>>a[i],s+=a[i]; > } > void main() > { > int a[64],b[64],sa,sb,n,i,j,an,bn,t,d1,d2; > cin>>n; > an = n/2; > bn = n-an; > in(an,a,sa); > in(bn,b,sb); > for(t=0;t<1000;++t) > { > i = rand()%an; > j = rand()%bn; > d1 = AS(sa-sb); > d2 = AS(sa-sb-((a[i]-b[j])<<1)); > if(d1 >= d2) > { > sa -= a[i] - b[j]; > sb -= b[j] - a[i]; > d1 = a[i]; > a[i] = b[j]; > b[j] = a[i]; ~~~~~~~~~~~~~~~~~~~~~b[j] = d1; > } > } > if(sa<sb) > cout<<sa<<" "<<sb; > else > cout<<sb<<" "<<sa; > cout<<endl; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator