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

求解 为什么老是Time Limit Exceeded啊!!!!

Posted by gong782008371 at 2013-01-28 16:13:27 on Problem 2965
#include<iostream>
#include<cstring>
using namespace std;
char ma[5][5];//用于输入
int state;

void shuru()
{
	int i;
	state=0;
	for(i=0;i<4;i++){
		cin>>ma[i];
		int j;
		for(j=0;j<4;j++)
			if(ma[i][j]=='+')
				state|=1<<(i*4+j);
	}
}

//反转一个,并产生影响
int fanzhuan(int stat,int i)
{
	int state=0;
	state|=1<<i;
	int j;
	for(j=0;j<4;j++){
		if(j!=i%4)state|=1<<(i-i%4+j);
		if(j!=i/4)state|=1<<(j*4+i%4);
	}
	return (state^stat);
}

//输出坐标
void print(int i)
{
	int j;
	for(j=0;(1<<j)<=i;j++)
		if((1<<j)&i)cout<<j/4+1<<" "<<j%4+1<<endl;
}

bool bbb()
{
	int i;
	for(i=0;i<(1<<16);i++)
	{
		int j,states=state;
		for(j=0;(1<<j)<=i;j++)
			if((1<<j)&i)
				states=fanzhuan(states,j);
		if(states==0){
			int count=0;
			for(j=0;j<16;j++)
				if(1<<j&i)count++;
			cout<<count<<endl;
			print(i);
			return true;
		}
	}
	return false;
}
int main()
{
	shuru();
	if(!bbb())cout<<"Impossible\n";
	return 0;
}

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