记录编号 |
117663 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[NOIP 2009]靶形数独 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.450 s |
提交时间 |
2014-08-30 20:33:44 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
int point[9][9]={6,6,6,6,6,6,6,6,6,
6,7,7,7,7,7,7,7,6,
6,7,8,8,8,8,8,7,6,
6,7,8,9,9,9,8,7,6,
6,7,8,9,10,9,8,7,6,
6,7,8,9,9,9,8,7,6,
6,7,8,8,8,8,8,7,6,
6,7,7,7,7,7,7,7,6,
6,6,6,6,6,6,6,6,6};
bool exist_in_line[10][10],exist_in_row[10][10],exist_in_square[10][10];
int sudoku[10][10];
int maxpoint=0;
//==============function declaration============
void countpoint();
void search(int row,int line);
//==============main code=======================
int main()
{
string FileName="sudoku";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
memset(exist_in_line,false,sizeof(exist_in_line));
memset(exist_in_row,false,sizeof(exist_in_row));
memset(exist_in_square,false,sizeof(exist_in_square));
For(i,0,8)
For(j,0,8)
{
scanf("%d",&sudoku[i][j]);
exist_in_line[j][sudoku[i][j]]=true;
exist_in_row[i][sudoku[i][j]]=true;
exist_in_square[i/3*3+j/3][sudoku[i][j]]=true;
}
search(8,8);
if (maxpoint!=0)
printf("%d\n",maxpoint);
else
printf("-1\n");
#ifdef DEBUG
clock_t End_Time=clock();
pritnf("\n\nTime Used: %.6lf",(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================
void search(int row,int line)
{
if (row==-1)
{
countpoint();
return ;
}
if (sudoku[row][line]!=0)
{
if (line==0)
search(row-1,8);
else
search(row,line-1);
return;
}
For(i,1,9)
{
if (!exist_in_line[line][i]&&!exist_in_row[row][i]&&!exist_in_square[row/3*3+line/3][i])
{
exist_in_line[line][i]=exist_in_row[row][i]=exist_in_square[row/3*3+line/3][i]=true;
sudoku[row][line]=i;
if (line==0)
search(row-1,8);
else
search(row,line-1);
exist_in_line[line][i]=exist_in_row[row][i]=exist_in_square[row/3*3+line/3][i]=false;
sudoku[row][line]=0;
}
}
return ;
}
void countpoint()
{
int sum=0;
For(i,0,8)
For(j,0,8)
sum+=sudoku[i][j]*point[i][j];
if (sum>maxpoint)
maxpoint=sum;
/*For(i,0,8)
{
For(j,0,8)
printf("%d ",sudoku[i][j]);
printf("\n");
}
printf("\n");
*/
return ;
}