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

求解答下,为什么同一段代码G++ WR,而C++ 却AC??

Posted by xiaozhuaixifu at 2013-10-03 13:51:15 on Problem 2676
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdio>
using namespace std;
int sudoku[9][9];
bool square[9][10];
bool checkrow[9][10];
bool checkcol[9][10];
bool isdone ; 
void dfs(int i, int j)
{
	if(i == 9) 
	{
		isdone = true;
		for(int i=0; i<9; i++)
		{
			for(int j=0; j<9; j++)
				cout<<sudoku[i][j];
			cout<<endl;
		}
		return ;
	}
	if(isdone) return ; 
	
	if(sudoku[i][j])
	{
		if(j == 8) dfs(i+1,0);
		else  dfs(i,j+1);
	}
	else
	{
		for(int num=1; num<10; num++)
		{
			int k = 3*(i/3)+j/3;
			
			if(!checkrow[i][num] && !checkcol[j][num] && !square[k][num])
			{
				sudoku[i][j] = num;
				checkrow[i][num] = 1;
			    checkcol[j][num] = 1;
				square[k][num] = 1; 
				if( j == 8)  dfs(i+1,0);
				else  dfs(i,j+1);
				
				sudoku[i][j] = 0;
				checkrow[i][num] = 0;
			    checkcol[j][num] = 0;
				square[k][num] = 0; 
				
			}
		}
	}
}
int main()
{
	int t;
	//ifstream fin;
	//fin.open("input.txt");
	//cout<<fin.is_open()<<endl;
	
	cin>>t;

	while(t--)
	{
		memset(square,0,sizeof(square));
		memset(checkcol,0,sizeof(checkcol));
		memset(checkrow,0,sizeof(checkrow));
		
		for(int i=0; i<9; i++)
		{
			char tmp[9];
			cin>>tmp;
			
			for(int j=0; j<9; j++)
			{
				sudoku[i][j] = tmp[j]-'0';
				if(sudoku[i][j])
				{
					int k = 3*(i/3)+j/3;
					checkrow[i][sudoku[i][j]] = 1;
					checkcol[j][sudoku[i][j]] = 1;
					square[k][sudoku[i][j]] = 1; 
				}
			}
		}
		isdone = false; 
		dfs(0,0);
	}
	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