CF538D.Weird Chess

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.

Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of pieces. Besides, all pieces in his game are of the same color. The possible moves of a piece are described by a set of shift vectors. The next passage contains a formal description of available moves.

Let the rows of the board be numbered from top to bottom and the columns be numbered from left to right from 1 to n. Let's assign to each square a pair of integers (x, y) — the number of the corresponding column and row. Each of the possible moves of the piece is defined by a pair of integers (dx, dy); using this move, the piece moves from the field (x, y) to the field (x + dx, y + dy). You can perform the move if the cell (x + dx, y + dy) is within the boundaries of the board and doesn't contain another piece. Pieces that stand on the cells other than (x, y) and (x + dx, y + dy) are not important when considering the possibility of making the given move (for example, like when a knight moves in usual chess).

Igor offers you to find out what moves his chess piece can make. He placed several pieces on the board and for each unoccupied square he told you whether it is attacked by any present piece (i.e. whether some of the pieces on the field can move to that cell). Restore a possible set of shift vectors of the piece, or else determine that Igor has made a mistake and such situation is impossible for any set of shift vectors.

伊戈尔玩国际象棋已经很久了,如今他对现行规则下的棋类游戏感到厌倦。他打算设计一套全新的规则,从而名扬世界。

伊戈尔的棋盘是一个 n×nn \times n 的方格。伊戈尔认为简洁的规则才能确保成功,因此他的新棋类游戏中仅有一种棋子类型,且所有棋子颜色相同。棋子的合法移动方式由一组位移向量(shift vectors)描述。下文将对合法移动作形式化定义。

设棋盘的行从上到下编号为 11 至 nn,列从左到右编号为 11 至 nn。我们用一对整数 (x,y)(x, y) 表示一个方格,其中 xx 为对应列号,yy 为对应行号。棋子的每一种合法移动由一对整数 (dx,dy)(dx, dy) 定义;执行该移动时,棋子从方格 (x,y)(x, y) 移动至方格 (x+dx,y+dy)(x + dx, y + dy)。当且仅当目标方格 (x+dx,y+dy)(x + dx, y + dy) 位于棋盘边界内,且该方格上没有其他棋子时,该移动才被允许。在判断某次特定移动是否可行时,除起始格 (x,y)(x, y) 和目标格 (x+dx,y+dy)(x + dx, y + dy) 外,其余方格上的棋子状态均不重要(例如,这与标准国际象棋中马的走法类似)。

伊戈尔请你推断出他的棋子可能具有的移动方式。他在棋盘上放置了若干枚棋子,并对每个空闲方格明确告知你:该方格是否被任意一枚现存棋子所攻击(即是否存在某枚棋子能一步移动到该方格)。你的任务是恢复出一组可能的位移向量;若不存在任何位移向量集合能产生所给定的攻击关系,则判定伊戈尔出错了,该情形不可能发生。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 50).

The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values:

  • o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some other piece;
  • x — in this case field (i, j) is attacked by some piece;
  • . — in this case field (i, j) isn't attacked by any piece.

It is guaranteed that there is at least one piece on the board.

第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)。

接下来的 nn 行,每行包含 nn 个字符,描述 Igor 提供的棋盘局面。第 ii 行的第 jj 个字符可以取以下值之一:

  • o — 此时格子 (i,j)(i, j) 上有一个棋子,且该格子可能被其他棋子攻击,也可能未被攻击;
  • x — 此时格子 (i,j)(i, j) 被某个棋子攻击;
  • . — 此时格子 (i,j)(i, j) 未被任何棋子攻击。

保证棋盘上至少存在一个棋子。

输出格式

If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2_n_ - 1) × (2_n_ - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the input. See examples of the output for a full understanding of the format. If there are several possible answers, print any of them.

If a valid set of moves does not exist, print a single word 'NO'.

如果存在一组合法的移动方式,则在第一行输出一个单词 “YES”(不带引号)。接下来,以与输入格式类似的方式,在一个 (2n−1)×(2n−1)(2n-1)\times(2n-1) 的棋盘上描述该棋子的移动方式:棋盘中心放置一枚棋子,用符号 'x' 标记所有该棋子能够攻击到的格子。参见输出样例以全面理解该格式。若存在多种可能的答案,输出任意一种即可。

若不存在合法的移动方式,则输出一个单词 “NO”。

输入输出样例

  • 输入#1

    5
    oxxxx
    x...x
    x...x
    x...x
    xxxxo

    输出#1

    YES
    ....x....
    ....x....
    ....x....
    ....x....
    xxxxoxxxx
    ....x....
    ....x....
    ....x....
    ....x....
  • 输入#2

    6
    .x.x..
    x.x.x.
    .xo..x
    x..ox.
    .x.x.x
    ..x.x.

    输出#2

    YES
    ...........
    ...........
    ...........
    ....x.x....
    ...x...x...
    .....o.....
    ...x...x...
    ....x.x....
    ...........
    ...........
    ...........
  • 输入#3

    3
    o.x
    oxx
    o.x

    输出#3

    NO

说明/提示

In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight.

在第一个样例测试中,棋子是普通的国际象棋车(rook);在第二个样例测试中,棋子是普通的国际象棋马(knight)。

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

首页