莱德,我需要你!
查看原帖
莱德,我需要你!
1238483
cqbzzlr楼主2024/8/17 14:01

已过样例,0pts求调,玄2关。


//  \\\\ \\ \\ \\ \\ \\ \\ \\ || || || || || || // // // // // // // ////
//  \\\\ \\ \\ \\ \\ \\ \\        _ooOoo_          // // // // // // ////
//  \\\\ \\ \\ \\ \\ \\          o8888888o            // // // // // ////
//  \\\\ \\ \\ \\ \\             88" . "88               // // // // ////
//  \\\\ \\ \\ \\                (| -_- |)                  // // // ////
//  \\\\ \\ \\                   O\  =  /O                     // // ////
//  \\\\ \\                   ____/`---'\____                     // ////
//  \\\\                    .'  \\|     |//  `.                      ////
//  //==                   /  \\|||  :  |||//  \                     ==\\
//  //==                  /  _||||| -:- |||||-  \                    ==\\
//  //==                  |   | \\\  -  /// |   |                    ==\\
//  //==                  | \_|  ''\---/''  |   |                    ==\\
//  //==                  \  .-\__  `-`  ___/-. /                    ==\\
//  //==                ___`. .'  /--.--\  `. . ___                  ==\\
//  //==             ."" '<  `.___\_<|>_/___.'  >' "".               ==\\
//  //==            | | :  `- \`.;`\ _ /`;.`/ - ` : | |              \\\\
//  ////            \  \ `-.   \_ __\ /__ _/   .-` /  /              \\\\
//  ////      ========`-.____`-.___\_____/___.-`____.-'========      \\\\
//  ////                           `=---='                           \\\\
//  //// //   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  \\ \\\\
//  //// // //      佛祖保佑      永无BUG      永不修改        \\ \\ \\\\
//  //// // // // // // || || || || || || || || || || \\ \\ \\ \\ \\ \\\\ 
#include <stack>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define IOS ios::sync_with_stdio(0);
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define SORT(x,y) sort(x+1,x+y+1)
#define UNQIUE(x,y) unqiue(x+1,x+y+1)
#define UPB(x,y,z) upper_bound(x+1,x+y+1,z)-x
#define LWB(x,y,z) lower_bound(x+1,x+y+1,z)-x
#define IT iterator

typedef long long ll;

const int N = 15;
const int INF = 0x3f3f3f3f;
const int eps = 1e-6;

inline int max(int x, int y) 
{
	if (x > y) return x;
	else return y;
}
inline int min(int x, int y) 
{
	if (x < y) return x;
	else return y;
}
inline void swap(int &x, int &y) 
{
	int t = x;
	x = y;
	y = t;
}
inline int pow(int x, int y)
{
	int ans = 1;
	while (y) {
		if (y % 2) ans *= x;
		x *= x;
		y = y >> 1;
	}
	return ans;
}
string s;
int a[N][N];
bool vis[N][N],vis1[N][N],vis2[N][N];
bool fg;
void dfs(int x,int y)
{
	if(fg) return ;
	if(x > 9)
	{
		rep(i,1,9)
		{
			rep(j,1,9)
			{
				cout << a[i][j];
			}
			cout << endl;
		}
		fg = true;
		return ;
	}
	int ny = y + 1,nx = x;
	if(ny > 9) ny = 1,nx++;
	if(a[x][y])
	{
		dfs(nx,ny);
		return ;
	}
	rep(i,1,9)
	{
		int c = (x - 1) / 3,l = (y + 2) / 3;
		int f = c * 3 + l;
		if(!vis[x][i] && !vis1[y][i] && !vis2[f][i])
		{
			vis[x][i] = vis1[y][i] = vis2[f][i] = 1;
			a[x][y] = i;
			dfs(nx,ny);
			a[x][y] = 0;
			vis[x][i] = vis1[y][i] = vis2[f][i] = 0;
		}
	}
	a[x][y] = 0;
}

inline void solve() 
{
	rep(i,1,9)
	{
		cin >> s;
		s = ' ' + s;
		rep(j,1,s.size() - 1)
		{
			int c = (i - 1) / 3,l = (j + 2) / 3;
			int f = c * 3 + l;
			a[i][j] = s[j] - '0';
			vis[i][a[i][j]] = vis1[j][a[i][j]] = vis2[f][a[i][j]] = 1;
		}
		//	cout << endl;
	}
	dfs(1,1);
}

signed main() {
	IOS;
	int T = 1;
	cin >> T;
	rep(fain, 1, T) {
		fg = false;
		solve();
	}
}
2024/8/17 14:01
加载中...