#P9628. [ICPC2020 Nanjing R] Go
[ICPC2020 Nanjing R] Go
题目描述
is an adversarial game with the objective of surrounding a larger total area of the board with one's stones than the opponent's. The core idea of the game is the concept of , which is an open point, or rather, an intersection of vertical and horizontal lines on the chessboard with no stones on it, bordering the group.
A stone, white or black, is called if it has at least one liberty directly orthogonally adjacent (up, down, left, or right), or must be in the same connected group with a stone of the same color which is alive. We say two stones of the same color are directly connected if they're orthogonally adjacent. We say two stones and of the same color are in the same connected group if there exists a sequence of stones such that for all , and are of the same color and are directly connected.
For example, in the left part of the below figure, neither of the two white stones is alive, as they're captured by the surrounding black stones; While in the right part, the rightmost white stone is also not alive, even if the leftmost black stone is also not alive.
Given a chessboard with vertical and horizontal lines where some stones might be lying on, please calculate the number of white stones captured by the black ones (that is to say, calcaulate the number of white stones not alive). The results for the above examples are and , respectively.
However, our dear friend Kotori thinks that this problem is too simple for our clever contestants to solve, so she would like to heat things up by instead asking you to flip the color of each stone (that is to say, change a black stone to a white one, or vice versa) independently and find out the corresponding answer after each flip.
By flipping independently we mean that before flipping the color of a stone, the other stones should change back to their original color. Also note that the data in this problem is not from the real world, which means that the size of the chessboard is not necesssarily , and the number of white and black stones can be any integer.
Vice versa: The reverse is also true. Here it can be replaced with change a white stone to a black one
. This is a very common phrase in modern English especially in academic writing, so please bear it in mind.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains one integer () indicating the length of the board side.
For the next lines, the -th line contains a string ( , , ), where indicates that the intersection on the -th row and the -th column contains a black stone. Similarly for a white stone and for an empty intersection.
It's guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case output an integer modulo which is the answer encoded as follows:
- Sort all the stones with their row number (from top to bottom) as the primary sort key and their column number (from left to right) as the secondary sort key;
- , where is the number of stones and is the number of white stones not alive after flipping the color of the -th stone.
$\underline{\text{NOTE that the MODULUS and the BASE are} \textbf{ DIFFERENT}}$. (We're begging you to notice this sentence. If this is not a pdf file I would rather it flashes and twinkles like crazy.)
题目大意
题目描述
围棋是一种对抗性游戏,目的是用自己的石头比对手的石头包围更大的棋盘总面积。游戏的核心理念是自由,即一个开放点,或者更确切地说,是棋盘上垂直线和水平线的交叉点,上面没有石头,与群体接壤。
一个白色或黑色的石头,如果它至少有一个直接正交相邻的自由(上、下、左或右),或者必须与一块有生命的相同颜色的石头在同一个连接组中,那么它是有生命的,被称为活着。我们说,如果两块颜色相同的石头正交相邻,它们就直接相连。如果存在一系列石头 ,对于所有 , 和 颜色相同且正交相邻,则相同颜色的两块石头 和 属于同一连通组。
例如,在下图的左侧,两块白色的石头都没有活着,因为它们被周围的黑色石头捕获了;而在右边的部分,最右边的白色石头也没有生命,即使最左边的黑色石头也没有。
给定一个有 条垂直线和 条水平线的棋盘,其中可能有一些石头躺在上面,请计算黑色石头捕获的白色石头的数量(也就是说,计算没有生命的白色石头数量)。上述例子的结果分别为 和 。
然而,我们亲爱的朋友 Kotori 认为这个问题让我们聪明的参赛者解决太简单了,所以她想让你独立翻转每块石头的颜色(也就是说,把黑色的石头变成白色的石头,反之亦然),并在每次翻转后找到相应的答案。
独立翻转的意思是,在翻转石头的颜色之前,其他石头应该变回原来的颜色。还要注意,这个问题中的数据不是来自真实世界,这意味着棋盘的大小不一定是 ,黑白石头的数量可以是任意整数。
反之亦然:在这里,它可以用 把白色的石头变成黑色的石头
来代替。这是现代英语中非常常见的短语,尤其是在学术写作中,所以请记住。
输入格式
有多个测试样例。输入的第一行包含一个整数 表示测试样例的数量。对于每个测试样例:
第一行包含一个整数 (),表示棋盘的边长。
对于接下来 行,第 行包含一个字符串 。其中 表示第 行第 列有一个黑石头, 表示第 行第 列有一个白石头, 表示第 行第 列是空的。
保证所有测试样例的 之和不超过 。
输出格式
对于每个测试用例输出一个整数 作为如下编码的答案:
- 对所有石头进行排序,以其行号(从上到下)为第一关键字,以其列号(从左到右)为第二关键字;
- ,其中 是石头的数量, 是翻转第 次颜色后没有生命的白色石头的数量。
$\underline{\textbf{注意}\text{:\textsf{模数}和\textsf{基数}是}\textbf{不同}{的}}$ 。(我们恳求你注意这句话。如果这不是 pdf 文件,我宁愿它像疯了一样闪烁。)
说明/提示
对于第二个测试样例,按照 的顺序翻转石头后,死亡的白色石头数量分别为 。
对于第三个测试样例,棋盘上的所有石头,无论是黑色还是白色,都不是活着的。
3
2
.o
..
3
.x.
xoo
ox.
2
oo
oo
0
870527216
485539347
提示
For the second sample test case, after flipping the stones in the order of , , , , , , the number of dead white stones are , , , , , , repectively.
For the third sample test case all stones on the chessboard, black or white, are not alive.