CF1450C1 题解

思路

对矩阵进行 (i+j)mod3(i+j)\bmod3 编号,只要改变其中一种颜色的所有 X 棋子就不会出现连续 33 个行列同色。

记得选最小的,最小的那个肯定 k3\le\lfloor\frac k3\rfloor

代码

# include <bits/stdc--.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
# define print(a) for (int i = 0; i < n; ++ i) cout << a[i] << '\n'; //我懒
int t, n, tot1, tot2, tot3;
string a[305], b[305], c[305];
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		tot1 = tot2 = tot3 = 0;
		cin >> n;
		for (int i = 0; i < n; ++ i) {
			cin >> a[i];
			c[i] = b[i] = a[i];
			for (int j = 0; j < n; ++ j)
				if (a[i][j] == 'X')
					if ((i + j) % 3 == 0)
						a[i][j] = 'O', ++ tot1;
					else if ((i + j) % 3 == 1)
						b[i][j] = 'O', ++ tot2;
					else
						c[i][j] = 'O', ++ tot3;
		}
		if (tot1 <= tot2 && tot1 <= tot3)
			print (a)
		else if (tot2 <= tot1 && tot2 <= tot3)
			print (b)
		else
			print (c)
	}
	return 0;
}
posted @   sz_jinzikai  阅读(2)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示