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

why RE!

Posted by xuguangshengqq at 2007-08-07 00:51:57 on Problem 2576
#include <iostream.h>
#include <memory.h>
//#include <fstream.h>
#include <math.h>


int a[45001][20];
int used[45001];
int d[101],n,cha,half,r,s,result,sum;


void set(int aa,int bb);
void set2(int index);

void main()
{  
   int i,j,min=4555555;
   //ifstream fin("in.txt");
   //fin>>n;
   cin>>n;
   sum = 0;
   for(i=1;i<=n;i++)
   {
    //fin>>d[i];
	   cin>>d[i];
	if(min>d[i])
	min = d[i];
	sum+=d[i];
   }
   /*Input is over!!*/
   
   memset(a,0,sizeof(a));
   memset(used,0,sizeof(used));
   half = sum/2;
   r = n/2;
   cha = 20000055;
   s = n - r;

   for(i=1;i<=n;i++)
   {  
	   set2(d[i]);
	   for(j=1;j<=sum;j++)
	   {
	     if(used[j]!=0&&j!=d[i])
		 {
		   set(d[i],d[j]);
		 }
	   }
   }
   if(result>(sum-result))
	   cout<<(sum-result)<<" "<<result<<endl;
   else  cout<<result<<" "<<(sum-result)<<endl;

   return;
}


void set(int aa,int bb)
{
	int i,j,k;
	int temp;
	for(i=1;i<=used[aa];i++)
	{
		for(j=1;j<=used[bb];j++)
		{
			temp = a[aa][i]+a[bb][j];
			for(k=1;k<=used[aa+bb];k++)
			{
			   if(a[aa+bb][k]==temp)break;
			}
			  if(k==(used[aa+bb]+1))
			  {	
				used[aa+bb]+=1;
			    a[aa+bb][k] = temp;
                  if((temp==r||temp==s)&&cha>abs(2*(aa+bb)-sum))
				  {
                       cha = abs(2*(aa+bb)-sum);
                       result = aa+bb;
				  }
			  }
		}
	}

}

void set2(int index)
{
  used[index]++;
  a[index][used[index]] = 1;
  if((n==2||n==3)&&cha>abs(2*index-sum))
  {
   cha = abs(2*index-sum);
   result = index;
  }
}

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