CF1221B.Knights
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x2, y2) from the cell (x1, y1) if one of the following conditions is met:
- ∣x1−x2∣=2 and ∣y1−y2∣=1, or
- ∣x1−x2∣=1 and ∣y1−y2∣=2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).

A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
你有一个 n 行 n 列的国际象棋棋盘。初始时,棋盘上所有格子均为空,你需要在每个格子中放置一个白色骑士或黑色骑士。
骑士是一种棋子,若其位于格子 (x1,y1),则它可以攻击位于格子 (x2,y2) 的棋子,当且仅当满足以下条件之一:
- ∣x1−x2∣=2 且 ∣y1−y2∣=1,或
- ∣x1−x2∣=1 且 ∣y1−y2∣=2。
以下是骑士可攻击格子的一些示例。在下列每张图中,若骑士当前位于蓝色格子,则它可以攻击所有红色格子(且仅能攻击这些格子)。

骑士对决(duel of knights)指一对颜色不同的骑士,且二者彼此攻击。你需要在每个格子中放置一个骑士(白色或黑色),使得骑士对决的总数尽可能大。
输入格式
The first line contains one integer n (3≤n≤100) — the number of rows (and columns) in the board.
第一行包含一个整数 n(3≤n≤100)——棋盘的行数(也是列数)。
输出格式
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
打印 n 行,每行包含 n 个字符。第 i 行的第 j 个字符应为 W(若格子 (i,j) 中放置了一个白方骑士),或 B(若其中放置了一个黑方骑士)。要求决斗次数尽可能多。若存在多个最优解,输出任意一个即可。
输入输出样例
输入#1
3
输出#1
WBW BBB WBW
说明/提示
In the first example, there are 8 duels:
- the white knight in (1, 1) attacks the black knight in (3, 2);
- the white knight in (1, 1) attacks the black knight in (2, 3);
- the white knight in (1, 3) attacks the black knight in (3, 2);
- the white knight in (1, 3) attacks the black knight in (2, 1);
- the white knight in (3, 1) attacks the black knight in (1, 2);
- the white knight in (3, 1) attacks the black knight in (2, 3);
- the white knight in (3, 3) attacks the black knight in (1, 2);
- the white knight in (3, 3) attacks the black knight in (2, 1).
在第一个例子中,共有 8 场对决:
- 位于 (1,1) 的白方骑士攻击位于 (3,2) 的黑方骑士;
- 位于 (1,1) 的白方骑士攻击位于 (2,3) 的黑方骑士;
- 位于 (1,3) 的白方骑士攻击位于 (3,2) 的黑方骑士;
- 位于 (1,3) 的白方骑士攻击位于 (2,1) 的黑方骑士;
- 位于 (3,1) 的白方骑士攻击位于 (1,2) 的黑方骑士;
- 位于 (3,1) 的白方骑士攻击位于 (2,3) 的黑方骑士;
- 位于 (3,3) 的白方骑士攻击位于 (1,2) 的黑方骑士;
- 位于 (3,3) 的白方骑士攻击位于 (2,1) 的黑方骑士。
输入解题思路,AI测评打分。不知道怎么写?