CF1621A.Stable Arrangement of Rooks

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an n×nn \times n chessboard and kk rooks. Rows of this chessboard are numbered by integers from 11 to nn from top to bottom and columns of this chessboard are numbered by integers from 11 to nn from left to right. The cell (x,y)(x, y) is the cell on the intersection of row xx and collumn yy for 1≤x≤n1 \leq x \leq n and 1≤y≤n1 \leq y \leq n.

The arrangement of rooks on this board is called good, if no rook is beaten by another rook.

A rook beats all the rooks that shares the same row or collumn with it.

The good arrangement of rooks on this board is called not stable, if it is possible to move one rook to the adjacent cell so arrangement becomes not good. Otherwise, the good arrangement is stable. Here, adjacent cells are the cells that share a side.

Such arrangement of 33 rooks on the 4×44 \times 4 chessboard is good, but it is not stable: the rook from (1,1)(1, 1) can be moved to the adjacent cell (2,1)(2, 1) and rooks on cells (2,1)(2, 1) and (2,4)(2, 4) will beat each other.

Please, find any stable arrangement of kk rooks on the n×nn \times n chessboard or report that there is no such arrangement.

你有一个 n×nn \times n 的棋盘和 kk 个车(rook)。该棋盘的行从上到下依次编号为 11 到 nn,列从左到右依次编号为 11 到 nn。对于 1≤x≤n1 \leq x \leq n 和 1≤y≤n1 \leq y \leq n,单元格 (x,y)(x, y) 表示第 xx 行与第 yy 列相交处的格子。

若棋盘上车的摆放方式满足:任意一个车均未被另一个车攻击,则称其为好的摆放。

一个车会攻击所有与其位于同一行或同一列上的其他车。

若一种好的摆放还满足:存在某个车可移动至其一个相邻格子(即与其共享一条边的格子),使得移动后该摆放变为不好,则称这种好的摆放为不稳定的;否则,该好的摆放称为稳定的。


如图所示,在 4×44 \times 4 棋盘上放置 33 个车的这种摆放是好的,但不稳定:位于 (1,1)(1, 1) 的车可移至相邻格子 (2,1)(2, 1),此时位于 (2,1)(2, 1) 和 (2,4)(2, 4) 的两个车将互相攻击。

请找出 n×nn \times n 棋盘上 kk 个车的一个稳定摆放;若不存在这样的摆放,请报告无解。

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains two integers nn, kk (1≤k≤n≤401 \leq k \leq n \leq 40) — the size of the chessboard and the number of rooks.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 nn、kk(1≤k≤n≤401 \leq k \leq n \leq 40)—— 棋盘的大小以及车的数量。

输出格式

If there is a stable arrangement of kk rooks on the n×nn \times n chessboard, output nn lines of symbols . and R. The jj-th symbol of the ii-th line should be equals R if and only if there is a rook on the cell (i,j)(i, j) in your arrangement.

If there are multiple solutions, you may output any of them.

If there is no stable arrangement, output −1-1.

如果存在一个在 n×nn \times n 棋盘上的 kk 个车的稳定布局,则输出 nn 行由符号 . 和 R 组成的字符串。第 ii 行的第 jj 个符号应为 R 当且仅当在你的布局中,格子 (i,j)(i, j) 上放置了一个车。

若存在多个解,你可以输出其中任意一个。

若不存在稳定布局,则输出 -1。

输入输出样例

  • 输入#1

    5
    3 2
    3 3
    1 1
    5 2
    40 33

    输出#1

    ..R
    ...
    R..
    -1
    R
    .....
    R....
    .....
    ....R
    .....
    -1

说明/提示

In the first test case, you should find stable arrangement of 22 rooks on the 3×33 \times 3 chessboard. Placing them in cells (3,1)(3, 1) and (1,3)(1, 3) gives stable arrangement.

In the second test case it can be shown that it is impossbile to place 33 rooks on the 3×33 \times 3 chessboard to get stable arrangement.

在第一个测试用例中,你需要在 3×33 \times 3 的棋盘上找到一种放置 22 个车的稳定方案。将它们放在格子 (3,1)(3, 1) 和 (1,3)(1, 3) 即可构成稳定方案。

在第二个测试用例中,可以证明:无法在 3×33 \times 3 的棋盘上放置 33 个车以得到稳定方案。

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

首页