C1. Errich-Tac-Toe (Easy Version)

C1. Errich-Tac-Toe (Easy Version)

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

题目原文
The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version.

Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces.

In a Tic-Tac-Toe grid, there are n rows and n columns. Each cell of the grid is either empty or contains a token. There are two types of tokens: X and O. If there exist three tokens of the same type consecutive in a row or column, it is a winning configuration. Otherwise, it is a draw configuration.

The patterns in the first row are winning configurations. The patterns in the second row are draw configurations.
In an operation, you can change an X to an O, or an O to an X. Let k denote the total number of tokens in the grid. Your task is to make the grid a draw in at most ⌊k3⌋ (rounding down) operations.

You are not required to minimize the number of operations.

Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤300) — the size of the grid.

The following n lines each contain a string of n characters, denoting the initial grid. The character in the i-th row and j-th column is ‘.’ if the cell is empty, or it is the type of token in the cell: ‘X’ or ‘O’.

It is guaranteed that not all cells are empty.

In the easy version, the character ‘O’ does not appear in the input.

The sum of n across all test cases does not exceed 300.

Output
For each test case, print the state of the grid after applying the operations.

We have proof that a solution always exists. If there are multiple solutions, print any.

Example
inputCopy
3
3
.X.
XXX
.X.
6
XX.XXX
XXXXXX
XXX.XX
XXXXXX
XX.X.X
XXXXXX
5
XXX.X
.X…X
XXX.X
…X…
…X…
outputCopy
.X.
XOX
.X.
XX.XXO
XOXXOX
OXX.XX
XOOXXO
XX.X.X
OXXOXX
XOX.X
.X…X
XXO.O
…X…
…X…
Note
In the first test case, there are initially three ‘X’ consecutive in the second row and the second column. By changing the middle token to ‘O’ we make the grid a draw, and we only changed 1≤⌊5/3⌋ token.

In the second test case, we change only 9≤⌊32/3⌋ tokens, and there does not exist any three ‘X’ or ‘O’ consecutive in a row or column, so it is a draw.

In the third test case, we change only 3≤⌊12/3⌋ tokens, and the resulting grid is a draw.

阴间题 可太艹了。一看,只有不到1k的人ac了,就感觉不对劲。但又是一个上分的大好时机啊。我们要抓住机会啊,和xdm半夜12点魔改代码,十字架处理,四角处理,面对答案编程。啊,这样例都过了,差不多了!这波先交一手,很快啊,第二个数据点就WA了。不过没事啊,再改改,再来一发,也是很快啊。第二个数据点又WA了。不改了,睡觉。。。仔细想想,自己的确实不是可行解。。来个全为X的图根本处理不了。。不说了,看答案。

思维题

这一看答案,很快啊,我就懂了。

在这里插入图片描述

原来是这个意思。。什么??你还没懂?

算了,说了也白说 把图标上坐标,i,j。则每一条斜线上的X都记为(i+j)%3. 用cnt[0],cnt[1],cnt[2]数组记下。那么,我们只要算算cnt最小的那个,把里面的X都处理掉就行。这样子为什么小于3/k的下取整题解叫了,另外的话这样子X为什么成不了三个也很明显呢?因为用一条条斜线来看, 只有三条斜线都取到X,才有可能X连线。

最后 在这里插入图片描述

懂的都懂

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值