A9945 | Sea and Islands
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A map of some object is a rectangular field consisting of $n$ rows and $n$ columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly $k$ islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island).
Find a way to cover some cells with sand so that exactly $k$ islands appear on the $n×n$ map, or determine that no such way exists.
Find a way to cover some cells with sand so that exactly $k$ islands appear on the $n×n$ map, or determine that no such way exists.
输入格式
The single line contains two positive integers $n$ , $k$ ( $1<=n<=100$ , $0<=k<=n^{2}$ ) — the size of the map and the number of islands you should form.
输出格式
If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next $n$ lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal $n$ .
If there are multiple answers, you may print any of them.
You should not maximize the sizes of islands.
Otherwise, print "YES" in the first line. In the next $n$ lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal $n$ .
If there are multiple answers, you may print any of them.
You should not maximize the sizes of islands.
输入输出样例
输入 #1
5 2
输出 #1
YES SSSSS LLLLL SSSSS LLLLL SSSSS
输入 #2
5 25
输出 #2
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted