这题真纠结,wa中夹杂这tle,还不知什么原因,最后也不知道改了哪,结果A了.....
code
/*
ID: yueqiq
PROG: numtri
LANG: C++
*/
#include <set>
//#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
const int maxn = 1001;
const int INF = 1111;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
using namespace std;
struct node{
int x,y;
}a[81];
int map[10][10],k=0;
bool flag=false;
bool is(int i,int x,int y){
FOR(j,1,9){
if(i==map[x][j]) return false;
if(i==map[j][y]) return false;
}
int k1=(x-1)/3;
int k2=(y-1)/3;
FOR(j,k1*3+1,k1*3+3) FOR(k,k2*3+1,k2*3+3){
if(i==map[j][k]) return false;
}
return true;
}
void dfs(int p){
if(p>=k){
FOR(i,1,9){
FOR(j,1,8){
PD(map[i][j]);PS;
}
printf("%d\n",map[i][9]);
}
flag=true;
return ;
}else{
FOR(i,1,9){
if(flag) break;
if(!is(i,a[p].x,a[p].y)) continue;
map[a[p].x][a[p].y]=i;
//printf("x:%d y:%d tian %d\n",a[p].x,a[p].y,i);
dfs(p+1);
map[a[p].x][a[p].y]=0;
}
}
return ;
}
int main()
{
readf;
writef;
int cas=0;
char s[2];
while(~scanf("%s",s) && s[0]!='\0'){
flag=false;
SET(map,0);
k=0;
FOR(i,1,9) FOR(j,1,9){
if(!(i==1&&j==1)) scanf("%s",s);
if(s[0]=='?'){
a[k].x=i;
a[k++].y=j;
map[i][j]=0;
}else{
map[i][j]=s[0]-'0';
}
}
//PD(k);LN;
if(cas++) LN;
dfs(0);
}
return 0;
}