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

TLE代码求修改

Posted by Algor at 2009-12-15 22:11:10 on Problem 1014 and last updated at 2009-12-15 22:13:07
#include<iostream>
using namespace std;
int a[7];
int sum;
bool marked[60002];
bool notend()
{
	sum=0;
	for(int i=1;i<7;i++)
	{
		scanf("%d",a+i);
		sum+=i*a[i];
	}
	if(sum==0)
		return false;
	return true;
}
bool ismarked(int n)
{
	if(marked[n])
		return true;
	if(n<7)
	{
		if(a[n])
		{
			marked[n]=true;
			a[n]--;
			return true;
		}
		return false;
	}
	for(int i=n/2;i>0;i--)
	{
		if(ismarked(i)&&ismarked(n-i))
		{
			marked[n]=true;
			return true;
		}
	}
	return false;
}
bool dividable()
{
	if(sum%2)
		return false;
	sum/=2;
	memset(marked,0,sizeof(bool));
	if(ismarked(sum))
		return true;
	return false;
}
int main()
{
	int c=0;
	while(notend())
	{
		cout<<"Collection #"<<++c<<":"<<endl;
		if(dividable())
			cout<<"Can be divided."<<endl;
		else
			cout<<"Can't be divided."<<endl;
		cout<<endl;
	}
	return 0;
}

例如这组测试数据就很慢:0 0 0 0 0 61

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