题意:
给一个数独的状态,判断它是否合法。
分析:
水,直接判断。
代码:
//poj 3435
//sep9
#include <iostream>
using namespace std;
const int maxN=10;
const int MAX=maxN*maxN+10;
int a[MAX][MAX];
int col_check[MAX][MAX];
int row_check[MAX][MAX];
int grid_check[MAX][MAX];
int n,c,r;
bool check()
{
	memset(row_check,0,sizeof(row_check));
	memset(col_check,0,sizeof(col_check));
	memset(grid_check,0,sizeof(grid_check));
	for(int i=0;i<r;++i)
		for(int j=0;j<c;++j)
			if(a[i][j]!=0){
				if(row_check[i][a[i][j]]!=0)
					return false;
				if(col_check[j][a[i][j]]!=0)
					return false;
				int g=i/n*n+j/n;
				if(grid_check[g][a[i][j]]!=0)
					return false; 
				row_check[i][a[i][j]]=1;
				col_check[j][a[i][j]]=1;
				grid_check[g][a[i][j]]=1;	
			}
	return true;
}
int main()
{
	scanf("%d",&n);
	c=r=n*n;
	for(int i=0;i<r;++i)
		for(int j=0;j<c;++j)
			scanf("%d",&a[i][j]);
	if(check())
		puts("CORRECT");
	else
		puts("INCORRECT");
	return 0;	
} 原文地址:http://blog.csdn.net/sepnine/article/details/45315477