309077: CF1621A. Stable Arrangement of Rooks

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Stable Arrangement of Rooks

题意翻译

你有一个 $n \times n$ 的棋盘,又给你了 $k$ 个车(这里的车可以上下左右移动任意步数,但不能走出棋盘之外),我们定义一个把这些车放到棋盘上的状态是稳定的当它满足: - 车不能攻击(即移动到另一个棋子的位置上)到另一个车 - 如果任意一个车上下左右任意移动一格,仍然满足第一条 请你给出任意一种将这些车放到棋盘上的稳定状态,如果没有,输出 `-1` 即可。 **【数据范围】** - $t$ 组数据,$1 \le t \le 100$ - $1 \le k,n \le 40$

题目描述

You have an $ n \times n $ chessboard and $ k $ rooks. Rows of this chessboard are numbered by integers from $ 1 $ to $ n $ from top to bottom and columns of this chessboard are numbered by integers from $ 1 $ to $ n $ from left to right. The cell $ (x, y) $ is the cell on the intersection of row $ x $ and collumn $ y $ for $ 1 \leq x \leq n $ and $ 1 \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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1621A/623b9e9d69019bc5c5f108d5afe045f1db44d516.png)Such arrangement of $ 3 $ rooks on the $ 4 \times 4 $ chessboard is good, but it is not stable: the rook from $ (1, 1) $ can be moved to the adjacent cell $ (2, 1) $ and rooks on cells $ (2, 1) $ and $ (2, 4) $ will beat each other.Please, find any stable arrangement of $ k $ rooks on the $ n \times n $ chessboard or report that there is no such arrangement.

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \leq t \leq 100 $ ) — the number of test cases. The first line of each test case contains two integers $ n $ , $ k $ ( $ 1 \leq k \leq n \leq 40 $ ) — the size of the chessboard and the number of rooks.

输出格式


If there is a stable arrangement of $ k $ rooks on the $ n \times n $ chessboard, output $ n $ lines of symbols . and R. The $ j $ -th symbol of the $ i $ -th line should be equals R if and only if there is a rook on the cell $ (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

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 $ 2 $ rooks on the $ 3 \times 3 $ chessboard. Placing them in cells $ (3, 1) $ and $ (1, 3) $ gives stable arrangement. In the second test case it can be shown that it is impossbile to place $ 3 $ rooks on the $ 3 \times 3 $ chessboard to get stable arrangement.

Input

题意翻译

你有一个 $n \times n$ 的棋盘,又给你了 $k$ 个车(这里的车可以上下左右移动任意步数,但不能走出棋盘之外),我们定义一个把这些车放到棋盘上的状态是稳定的当它满足: - 车不能攻击(即移动到另一个棋子的位置上)到另一个车 - 如果任意一个车上下左右任意移动一格,仍然满足第一条 请你给出任意一种将这些车放到棋盘上的稳定状态,如果没有,输出 `-1` 即可。 **【数据范围】** - $t$ 组数据,$1 \le t \le 100$ - $1 \le k,n \le 40$

加入题单

算法标签: