Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:CODE

Posted by T3 at 2005-08-17 00:09:37 on Problem 2576
In Reply To:能给出伪代码吗 Posted by:egmna at 2005-08-16 12:37:53
#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];
		}
	}
	if(sa<sb)
		cout<<sa<<" "<<sb;
	else
		cout<<sb<<" "<<sa;
	cout<<endl;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator