Even If the World TurnsAI (CI翻译)
Now, no matter what anyone says, I am the happiest girl in the world.— Chtholly
This is a run-twice (communication) problem.
At the Fairy Warehouse, Nygglatho prepared an unusual game for Chtholly and Willem.
They would be separated and unable to exchange a single word. Between them there would be only a black-and-white picture — one that Nygglatho could shift, rotate, reflect, or even invert its colors.
Nygglatho saw it as a test of how well they understood each other. Chtholly and Willem perhaps saw only another kind of promise. No matter how the world turned, they would still find the same place.
The two players are Chtholly and Willem. The jury, acting as Nygglatho, first communicates with Chtholly. After Chtholly finishes, the jury communicates with Willem. Chtholly and Willem may agree on the strategy they will use beforehand, but they cannot directly pass information to each other.
In each test case, Nygglatho prepares a black-and-white picture consisting of $n \times n$ cells and chooses a target cell $x$. The rows and columns are numbered from $1$ to $n$.
The picture contains $w$ black cells. It is guaranteed that $\gcd(n,w)=1$.
Nygglatho first shows the picture and the target cell $x$ to Chtholly. Chtholly must choose two cells and swap their colors. The two cells are allowed to be the same. If they are the same, or if they have the same color, the picture does not change. She cannot send Willem any other information.
Swapping colors does not move the target cell.
Nygglatho then secretly transforms the picture. She may perform the following operations any number of times, possibly zero, in any order:
- Choose two integers
$d_r$and$d_c$($0\le d_r,d_c \lt n$) and cyclically shifts the picture. Every cell$(r,c)$moves to$\left(\left(r-1+d_r\right)\bmod n+1,\left(c-1+d_c\right)\bmod n+1\right)$; - Rotate the picture clockwise by
$90^\circ$. One such rotation moves every cell$(r,c)$to$(c,n+1-r)$; - Reflect the picture across its vertical axis. Such a reflection moves every cell
$(r,c)$to$(r,n+1-c)$; - Invert all colors. This changes every black cell into a white cell and every white cell into a black cell.
The target cell $x$ undergoes every cyclic shift, rotation, and reflection in exactly the same way as the picture. Color inversions do not move it.
Finally, Nygglatho shows only the resulting picture to Willem. Willem must determine the final position of $x$.
Your program will be run exactly twice on each test. On the first run, it must act as Chtholly. On the second run, it must act as Willem. No information is preserved between the two runs except for the information passed by the jury according to the rules above.
The order of the test cases may be changed between the two runs.
First Run
On the first run, you are Chtholly.
Input
The first line contains the string first, indicating that this is the first run.
After this line, the remaining input has the following format.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($2 \le n \le 800$) — the height and width of the picture.
Each of the next $n$ lines contains a string of length $n$. The character $\mathtt{\#}$ denotes a black cell, and the character $\mathtt{.}$ denotes a white cell.
The next line contains two integers $r_x$ and $c_x$ ($1 \le r_x,c_x \le n$) — the row and column of the target cell $x$.
Let $w$ be the number of black cells in the picture. It is guaranteed that $\gcd(n,w)=1$.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $800^2$.
Output
For each test case, output four integers $r_1$, $c_1$, $r_2$, and $c_2$ ($1 \le r_1,c_1,r_2,c_2 \le n$) — the two cells whose colors Chtholly chooses to swap. The two cells are allowed to be the same.
Second Run
On the second run, you are Willem.
Input
The first line contains the string second, indicating that this is the second run.
After this line, the remaining input has the following format.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The value of $t$ is the same as on the first run, although the test cases may appear in a different order.
The first line of each test case contains the integer $n$ ($2 \le n \le 800$).
Each of the next $n$ lines contains a string of length $n$, describing the resulting picture after Chtholly's swap and Nygglatho's transformations for the corresponding test case from the first run. Again, $\mathtt{\#}$ denotes a black cell and $\mathtt{.}$ denotes a white cell.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $800^2$.
Output
For each test case, output two integers $r'_x$ and $c'_x$ ($1 \le r'_x,c'_x \le n$) — the row and column of the target cell after all transformations.
Hacks are disabled in this problem.
Note
The first example shows Chtholly's run for two test cases. The second example shows Willem's run for the same two test cases. The outputs shown for Chtholly's run are just one possible set of valid choices.
In the first test case, Chtholly swaps cells $(1,1)$ and $(4,1)$. Afterwards, the two black cells are at $(2,2)$ and $(4,1)$.
In this example, Nygglatho performs the following transformations.
- she cyclically shifts the picture one row down and two columns to the right;
- she rotates the picture clockwise by
$90^\circ$once; - she reflects the picture across its vertical axis;
The target moves from $(3,4)$ to $(4,1)$ after the cyclic shift, then to $(1,2)$ after the rotation, and finally to $(1,4)$ after the reflection. The two black cells finally arrive at $(3,5)$ and $(4,3)$, giving exactly the picture in Willem's run. Willem reports the target position $(1,4)$.
In the second test case, Chtholly can choose the same cell, in which case nothing changes. Nygglatho can then also choose to do nothing.
{"titleZh":"即使世界天翻地覆","bodyZh":"现在,无论别人说什么,我都是世界上最幸福的女孩。——珂朵莉\n\n这是一道运行两次(通信)问题。\n\n在妖精仓库中,妮戈拉托为珂朵莉和威廉准备了一场不同寻常的游戏。\n\n两人将被分开,无法交换任何信息。他们之间只有一张黑白图片,而妮戈拉托可以对图片进行平移、旋转、翻转,甚至反转颜色。\n\n妮戈拉托将此视为对两人相互理解程度的考验。或许在珂朵莉和威廉眼中,这只是另一种形式的约定。无论世界如何变化,他们都将找到同一个地方。\n\n两名玩家分别是珂朵莉和威廉。评测器扮演妮戈拉托,首先与珂朵莉进行通信。珂朵莉结束后,评测器再与威廉进行通信。珂朵莉和威廉可以提前约定所使用的策略,但不能直接互相传递信息。\n\n在每个测试用例中,妮戈拉托准备一张由 $n \\times n$ 个格子组成的黑白图片,并选择一个目标格子 $x$。行和列的编号均为 $1$ 到 $n$。\n\n图片中包含 $w$ 个黑色格子。保证 $\gcd(n,w)=1$。\n\n妮戈拉托首先将图片和目标格子 $x$ 展示给珂朵莉。珂朵莉必须选择两个格子并交换它们的颜色。两个格子可以是同一个格子。如果它们相同,或者颜色相同,则图片不会发生变化。除此之外,她不能向威廉传递任何信息。\n\n交换颜色不会移动目标格子。\n\n随后,妮戈拉托会秘密地变换图片。她可以按任意顺序执行以下操作任意次,也可以一次都不执行:\n\n1. 选择两个整数 $d_r$ 和 $d_c$($0\\le d_r,d_c \\lt n$),并对图片进行循环平移。每个格子 $(r,c)$ 会移动到 $\\left(\\left(r-1+d_r\\right)\\bmod n+1,\\left(c-1+d_c\\right)\\bmod n+1\\right)$;\n2. 将图片顺时针旋转 $90^\\circ$。一次旋转会将每个格子 $(r,c)$ 移动到 $(c,n+1-r)$;\n3. 将图片沿竖直轴反射。这样的反射会将每个格子 $(r,c)$ 移动到 $(r,n+1-c)$;\n4. 反转所有颜色。也就是说,将每个黑色格子变为白色格子,并将每个白色格子变为黑色格子。\n\n目标格子 $x$ 会随着图片进行每一次循环平移、旋转和反射,颜色反转不会移动目标格子。\n\n最后,妮戈拉托只将变换后的图片展示给威廉。威廉必须确定 $x$ 的最终位置。\n\n你的程序将在每个测试上恰好运行两次。第一次运行时,程序必须扮演珂朵莉;第二次运行时,程序必须扮演威廉。除了评测器按照上述规则传递的信息外,两次运行之间不会保留任何信息。\n\n两次运行之间可以改变测试用例的顺序。\n\n## 第一次运行\n\n在第一次运行中,你扮演珂朵莉。\n\n## 输入格式\n\n第一行包含字符串 first,表示这是第一次运行。\n\n在此行之后,剩余输入的格式如下。\n\n每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来描述各个测试用例。\n\n每个测试用例的第一行包含一个整数 $n$($2 \\le n \\le 800$),表示图片的高和宽。\n\n接下来的 $n$ 行中,每行包含一个长度为 $n$ 的字符串。字符 $\\mathtt{\\#}$ 表示黑色格子,字符 $\\mathtt{.}$ 表示白色格子。\n\n下一行包含两个整数 $r_x$ 和 $c_x$($1 \\le r_x,c_x \\le n$),表示目标格子 $x$ 的行和列。\n\n令 $w$ 表示图片中的黑色格子数。保证 $\gcd(n,w)=1$。\n\n保证所有测试用例的 $n^2$ 之和不超过 $800^2$。\n\n## 输出格式\n\n对于每个测试用例,输出四个整数 $r_1$、$c_1$、$r_2$ 和 $c_2$($1 \\le r_1,c_1,r_2,c_2 \\le n$),表示珂朵莉选择交换颜色的两个格子。两个格子可以是同一个格子。\n\n## 第二次运行\n\n在第二次运行中,你扮演威廉。\n\n## 输入格式\n\n第一行包含字符串 second,表示这是第二次运行。\n\n在此行之后,剩余输入的格式如下。\n\n每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来描述各个测试用例。\n\n$t$ 的值与第一次运行相同,但测试用例的顺序可能不同。\n\n每个测试用例的第一行包含整数 $n$($2 \\le n \\le 800$)。\n\n接下来的 $n$ 行中,每行包含一个长度为 $n$ 的字符串,表示对应测试用例在珂朵莉交换以及妮戈拉托进行变换后的图片。同样,$\\mathtt{\\#}$ 表示黑色格子,$\\mathtt{.}$ 表示白色格子。\n\n保证所有测试用例的 $n^2$ 之和不超过 $800^2$。\n\n## 输出格式\n\n对于每个测试用例,输出两个整数 $r'_x$ 和 $c'_x$($1 \\le r'_x,c'_x \\le n$),表示目标格子经过所有变换后的行和列。\n\n本题禁止提交 Hack。\n\n## 说明\n\n第一个样例展示了两个测试用例的珂朵莉运行过程。第二个样例展示了相同两个测试用例的威廉运行过程。珂朵莉运行中的输出只是满足条件的一组可能选择。\n\n在第一个测试用例中,珂朵莉交换了格子 $(1,1)$ 和 $(4,1)$。之后,两个黑色格子位于 $(2,2)$ 和 $(4,1)$。\n\n在这个例子中,妮戈拉托进行了以下变换:\n\n- 将图片向下循环平移一行,并向右循环平移两列;\n- 将图片顺时针旋转 $90^\\circ$ 一次;\n- 将图片沿竖直轴反射。\n\n目标格子在循环平移后从 $(3,4)$ 移动到 $(4,1)$,旋转后移动到 $(1,2)$,最后在反射后移动到 $(1,4)$。两个黑色格子最终到达 $(3,5)$ 和 $(4,3)$,这正好得到了威廉运行时的图片。威廉报告目标位置为 $(1,4)$。\n\n在第二个测试用例中,珂朵莉可以选择同一个格子,此时图片不会发生变化。随后,妮戈拉托也可以什么都不做。"}AI (CI翻译)
样例
first
2
5
#....
.#...
.....
.....
.....
3 4
5
.....
####.
.....
#####
.....
1 1
1 1 4 1
1 1 1 1
second
2
5
.....
####.
.....
#####
.....
5
.....
.....
....#
..#..
.....
1 1
1 4
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。