QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 32 MB 満点: 10

#10378. 车 [B]

統計

经过一番努力,Bytie 终于在 $n \times n$ 的棋盘上放置了 $n$ 个车,使得它们互不攻击。简单回顾一下:一个车会攻击与它处于同一行或同一列的所有棋盘格子$^{1}$。

不幸的是,Bytie 现在不小心撞到了棋盘,导致一些车从棋盘上掉了下来。你能帮 Bytie 把这些车放回棋盘上吗?Bytie 希望保持棋盘上现有的车不动。

  1. 参见 http://en.wikipedia.org/wiki/Rook_(chess))

输入格式

标准输入的第一行包含一个整数 $n$ ($2 \le n \le 1\,000$),表示棋盘的大小。接下来是棋盘上车的配置描述:接下来的 $n$ 行,每行包含 $n$ 个字符。字符 '.' 表示空位,字母 'W' 表示有车占据的格子。

你可以假设棋盘上现有 $w$ 个车,满足 $1 \le w \le n-1$,且棋盘上没有任何一对车互相攻击。

输出格式

你的程序应向标准输出打印 $n$ 行,每行包含 $n$ 个字符 '.' 或 'W',表示棋盘上车的最终配置。该描述应恰好包含 $n$ 个字母 'W',其中 $w$ 个车的位置与初始棋盘上的位置相同。任意两个车不得互相攻击。如果存在多种在初始棋盘上放置 $n - w$ 个车的方法,你的程序输出其中任意一种即可。

样例

输入

8
........
.....W..
..W.....
.......W
W.......
........
.W......
........

输出

...W....
.....W..
..W.....
.......W
W.......
....W...
.W......
......W.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.