TLE 求调
  • 板块P10482 Sudoku 2
  • 楼主FCB2012
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/7/19 11:34
  • 上次更新2025/7/19 17:38:28
查看原帖
TLE 求调
976389
FCB2012楼主2025/7/19 11:34
#include<bits/stdc++.h>
using namespace std;
int t,a[10][10],flag,h[10][10],l[10][10],m[10][10];
char c;
void dfs(int x,int y){
	if(x==9){
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				cout<<a[i][j];
			}
		}
		cout<<endl;
		flag=1;
		return;
	}
	if(flag==1){
		return; 
	}
	if(a[x][y]){
		dfs(x,y+1);
		return;
	}
	if(y==9){
		dfs(x+1,0);
		return;
	}
	int z=x/3*3+y/3;
	for(int i=1;i<=9;i++){
		if(!h[x][i]&&!l[y][i]&&!m[z][i]){
			a[x][y]=i;
			h[x][i]=l[y][i]=m[z][i]=1;
			dfs(x,y+1);
			a[x][y]=0;
			h[x][i]=l[y][i]=m[z][i]=0;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	while(1){
		memset(a,0,sizeof(a));
		memset(h,0,sizeof(h));
		memset(l,0,sizeof(l));
		memset(m,0,sizeof(m));
		flag=0;
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				cin>>c;
				if(c=='e'||c=='n'||c=='d')return 0; 
				if(c!='.'){
					a[i][j]=c-'0';
					h[i][c-'0']=l[j][c-'0']=m[i/3*3+j/3][c-'0']=1;
				}
			}
		}
		dfs(0,0);
	}
	return 0;
}

提交结果 实在是想不明白了,为什么会TLE呢(QwQ)

2025/7/19 11:34
加载中...