CF1450C1 题解
思路
对矩阵进行 编号,只要改变其中一种颜色的所有 X 棋子就不会出现连续 个行列同色。
记得选最小的,最小的那个肯定 。
代码
# 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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现