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

这样为什么过不了?

Posted by datouchong at 2006-03-26 18:34:44 on Problem 1681
#include <iostream.h>
#include <math.h>
bool puzzle[1000][1000];  
bool press[1000][1000];   
bool tmppuzzle[1000][1000]; 
void readInPuzzle(); 
void printPress();   
bool check(int x);   
int k;
void main()
{
	 int n,i;int flag=0;
	 cin >>n;
	 for(i=1;i<=n;i++){
		 //read in puzzle
		 readInPuzzle();
		 for(int j=0;j<(k+1)*(k+1);j++) 
		 {if(check(j))
		 {printPress();
			flag=1;
		 break;}
			}
if(flag==0)
cout<<"inf"<<endl;
	 }		

}
void readInPuzzle(){
     char tmp[1000][1000],i,j;
	 cin>>k;
     for(i=1;i<=k;i++)
		 for(j=1;j<=k;j++){
	        cin >> tmp[i][j];
			if(tmp[i][j]=='y')
			puzzle[i][j] = 0;
			else
				if(tmp[i][j]=='w')
				puzzle[i][j] = 1;
		 }
}
void printPress(){
     int i,j;int m=0;
	 for(i=1;i<=k;i++){
 	     for(j=1;j<=k;j++)
		 {
		 m=m+(int)press[i][j];}
	      
}
		cout<<m<<endl;
}
bool check(int x){//checking if set first line of press to x, 
	              // whether all lights are turned off
	int i,j;

	for(i=1;i<=k;i++)
		for(j=1;j<=k;j++)
			tmppuzzle[i][j] = puzzle[i][j];

	for(i=1;i<=k;i++){
       press[1][k+1-i]=(bool)(x%2);
	   x /= 2;
	}
	for(i=1;i<=k;i++){
		if(press[1][i]==true){
			tmppuzzle[1][i] = !tmppuzzle[1][i];
			tmppuzzle[1][i-1] = !tmppuzzle[1][i-1];
			tmppuzzle[1][i+1] = !tmppuzzle[1][i+1];
			tmppuzzle[2][i] = !tmppuzzle[2][i];
		}
	}
	int line;
	for(line = 2; line<=k; line++){
		  for(i=1;i<=k;i++)
			  press[line][i] = tmppuzzle[line-1][i];		  
	      for(i=1;i<=k;i++){
		     if(press[line][i]==true){
			    tmppuzzle[line][i] = !tmppuzzle[line][i];
			    tmppuzzle[line][i-1] = !tmppuzzle[line][i-1];
			    tmppuzzle[line][i+1] = !tmppuzzle[line][i+1];
			    tmppuzzle[line-1][i] = !tmppuzzle[line-1][i];
			    tmppuzzle[line+1][i] = !tmppuzzle[line+1][i];
			 }
		  }
	}
	bool ret = false;
	for(i=1;i<=k;i++) ret = ret || tmppuzzle[k][i];
    return !ret;  
}

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