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 hfhhxh at 2012-04-15 15:37:22 on Problem 2965
#include<stdio.h>
#include<string.h>
int main()
{
	char s[4];
	int map[4][4];
	int i,j,k;
	int step=20,path;
	for(i=0;i<4;i++)
	{
		scanf("%s",s);
		for(j=0;j<4;j++)
			if(s[j]=='-')map[i][j]=1;
			else {map[i][j]=0;}
	}
	for(k=0;k<1<<16;k++)
	{
		int t[4][4];
		memcpy(t,map,sizeof(map));
		int c=0;
		for(i=0;i<16;i++)
		{
			if(k>>i&1) 
			{
				c++;
				int x=i/4,y=i%4;
				t[x][y]=!t[x][y];
				for(int x1=0;x1<4;x1++)t[x1][y]=!t[x1][y];
				for(int y1=0;y1<4;y1++)t[x][y1]=!t[x][y1];
			}
		}
		int num=0;
		for(i=0;i<4;i++)
			for(j=0;j<4;j++)
				if(t[i][j])num++;
		if(num==16)
		{
			if(c<step){step=c;path=k;}
		}
	}
	printf("%d\n",step);
	for(i=0;i<16;i++)
	{
		if(1<<i&path)printf("%d %d\n",i/4+1,i%4+1);
	}
	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