codeforces-544B-Sea and Islands【构造】
来源:互联网 发布:软件测试很难吗 编辑:程序博客网 时间:2024/06/02 03:13
codeforces-544B-Sea and Islands
time limit per test1 second memory limit per test256 megabytes
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.
Input
The single line contains two positive integers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ n2) — the size of the map and the number of islands you should form.
Output
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.
input
5 2
output
YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS
input
5 25
output
NO
题目链接:cf-544B
题目大意:构造n*n矩形,使得存在k个L不相连。
题目思路:构造题构造形如:
5 13
LSLSL
SLSLS
LSLSL
SLSLS
LSLSL
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){ int n,k,ret; cin >> n >> k; if (n % 2) ret = (n + 1) / 2 + (n - 1) / 2 * n; else ret = n * n / 2; if (k > ret) cout << "NO\n"; else { cout << "YES\n"; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i % 2 == j % 2) { if (k) { cout << "L"; k--; } else cout << "S"; } else cout << "S"; } cout << "\n"; } } return 0;}
- codeforces-544B-Sea and Islands【构造】
- Codeforces 544B - Sea and Islands(构造)
- Codeforces#302-B-Sea and Islands-水题
- Codeforces Round #302 (Div. 2) B. Sea and Islands
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- Codeforces544B:Sea and Islands
- 【codeforces】477B Dreamoon and Sets 构造
- codeforces 738D Sea Battle 思维+构造
- Codeforces 388B Fox and Minimal path(构造)
- codeforces 553B Kyoya and Permutation 构造+规律
- CodeForces 477B-E - Dreamoon and Sets-构造规律题
- Codeforces 639B Bear and Forgotten Tree 3 【构造】
- Codeforces 388B Fox and Minimal path(构造)
- Codeforces 771B Bear and Different Names[构造]
- CodeForces 639 B.Bear and Forgotten Tree 3(构造)
- CodeForces 643 B.Bear and Two Paths(构造)
- Codeforces Round #380 Div. 1 B. Sea Battle(贪心)
- Codeforces 605B 构造
- SpingMVC IReport多数据源交叉报表示例
- vba 删除行
- Spring事务控制
- 谁删了我的博客
- 书摘——《轮下》赫尔曼·黑塞
- codeforces-544B-Sea and Islands【构造】
- 遍历DOM
- Android笔记—应用更新
- B. OR in Matrix
- spring 加载property文件的方式
- matlab 绘制 3d 心
- 欧拉函数
- 驱动开发(4)内核中的内存分配和错误码
- Javascript静态变量与实例变量