CF907B.Tic-Tac-Toe

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.

The game is played on the following field.

Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (x__l, y__l) in some small field, the next move should be done in one of the cells of the small field with coordinates (x__l, y__l). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.

You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.

A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.

两只熊通过邮件玩井字棋。对于它们来说,玩普通的井字棋太无聊了,因此它们正在玩这种游戏的一个变种。规则如下:

游戏在如下棋盘上进行:

双方轮流走子。第一步,玩家可将棋子放入任意一个小棋盘的任意空格中。后续每一步均有一些限制:若上一手对方玩家将棋子下在某个小棋盘内坐标为 (xl, yl)(x_l,\,y_l) 的格子中,则当前玩家的下一步必须下在坐标为 (xl, yl)(x_l,\,y_l) 的那个小棋盘内的某个空格中。例如,若第一步玩家将棋子下在中央小棋盘的左下角格子中,则第二位玩家的下一步就必须下在左下角小棋盘中的某个空格内(请参见第一个样例测试用例)。如果所要求的小棋盘中已无空格,则当前玩家可将棋子下在任意小棋盘的任意空格中。

现给出游戏的当前局面以及上一手所下位置的坐标,你需要找出当前玩家所有可以落子的位置。

森林里有一只野兔担任邮递员,它喜欢捉弄熊。有时它会略微改动一下棋盘,使得当前局面可能根本无法通过合法走法到达。然而,在它改动之后,上一手所下位置的格子一定不是空的。你无需判断当前局面是否可达,只需依据上述规则输出所有可能的下一步落子位置即可。

输入格式

First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.

The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.

It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.

前 11 行描述了一个 9 行 9 列的棋盘,棋盘被空格和空行划分为 9 个小区块。每个小区块由 9 个字符(不含空格和空行)描述。字符 "x"(ASCII 码为 120)表示该格子被第一位玩家的棋子占据;字符 "o"(ASCII 码为 111)表示该格子被第二位玩家的棋子占据;字符 "."(ASCII 码为 46)表示该格子为空。

棋盘描述之后的一行包含两个整数 xx 和 yy(1≤x,y≤91 \le x, y \le 9),表示上一手落子所在的格子坐标。棋盘的行从上到下编号,列从左到右编号。

保证上一手落子所在的格子内容为 "x" 或 "o"。同时保证棋盘中至少存在一个空格子。注意:当前棋局状态未必是可达的。

输出格式

Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.

在相同格式的棋盘中,将当前玩家可以放置棋子的位置用字符“!”(ASCII码为33)表示。其余所有格子保持不变。

输入输出样例

  • 输入#1

    ... ... ...
    ... ... ...
    ... ... ...
    
    ... ... ...
    ... ... ...
    ... x.. ...
    
    ... ... ...
    ... ... ...
    ... ... ...
    6 4

    输出#1

    ... ... ... 
    ... ... ... 
    ... ... ... 
    
    ... ... ... 
    ... ... ... 
    ... x.. ... 
    
    !!! ... ... 
    !!! ... ... 
    !!! ... ...
  • 输入#2

    xoo x.. x..
    ooo ... ...
    ooo ... ...
    
    x.. x.. x..
    ... ... ...
    ... ... ...
    
    x.. x.. x..
    ... ... ...
    ... ... ...
    7 4

    输出#2

    xoo x!! x!! 
    ooo !!! !!! 
    ooo !!! !!! 
    
    x!! x!! x!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    x!! x!! x!! 
    !!! !!! !!! 
    !!! !!! !!!
  • 输入#3

    o.. ... ...
    ... ... ...
    ... ... ...
    
    ... xxx ...
    ... xox ...
    ... ooo ...
    
    ... ... ...
    ... ... ...
    ... ... ...
    5 5

    输出#3

    o!! !!! !!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    !!! xxx !!! 
    !!! xox !!! 
    !!! ooo !!! 
    
    !!! !!! !!! 
    !!! !!! !!! 
    !!! !!! !!!

说明/提示

In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.

In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.

In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.

在第一个测试用例中,先手玩家将棋子下到了中央区域的左下角格子,因此后手玩家只能将棋子下到左下区域的格子中。

在第二个测试用例中,上一步操作是将棋子下到了下中区域的左上角格子,但左上区域的所有格子均已占满,因此后手玩家可以将棋子下到任意一个空格中。

在第三个测试用例中,上一步操作是将棋子下到了中央区域的中心格子,因此当前玩家可以将棋子下到中央区域的任意格子中;但中央区域已全部占满,故当前玩家可将棋子下到任意空格中。请注意:该游戏状态实际上不可达。

输入解题思路,AI测评打分。不知道怎么写?

首页