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

杯具了,AC了的程序运行了半天也没个结果~~我以前WA的程序是秒杀的……

Posted by wsj19911101 at 2010-11-27 07:45:47 on Problem 1011
In Reply To:一组比较BT的数据! Posted by:winboycool at 2007-04-22 00:07:27
#include<iostream>
#include<algorithm>
using namespace std;
int s[65];
int n;
int x;
bool bfs(int sum,int m)
{
	if(sum==0)
	{
		m--;
		if(m==0)return true;
		else if(bfs(x,m)==false)return false;
		else return true;
	}
	else if(sum==x)
	{
		int i=n;
        do{i--;}while(s[i]<0);
		s[i]=-s[i];
		if(bfs(sum+s[i],m)==false){s[i]=-s[i];return false;}
		return true;
	}
	else 
	{
		int i=n;
		goto check;
check:do{i--;}while((i>=0)&&(s[i]<0||s[i]>sum||s[i]==s[i+1]));
		if(i>=0)
		{   s[i]=-s[i];
		    if(bfs(sum+s[i],m)==false){s[i]=-s[i];goto check;}
			return true;
		}
		else return false;
	}
}
int main()
{
	while(cin>>n&&n)
	{
	    int sum=0;
		for(int i=0;i<n;i++){cin>>s[i];sum+=s[i];}
		sort(s,s+n);
		for(int i=n;i>0;i--)if(sum%i==0){x=sum/i;if(bfs(x,i)){cout<<x<<endl;break;}for(int i=0;i<n;i++)s[i]=abs(s[i]);}
	}
}

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