您的位置:首页 > 其它

CF Sea and Islands

2015-05-15 21:57 162 查看
Sea and Islands

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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.

Sample test(s)

input
5 2


output
YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS


input
5 25


output
NO

判下奇偶再输出就行了。人品爆发居然打到了200+,希望这样的狗屎运常来一些。


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <map>
#include <ctime>
using    namespace    std;

int    main(void)
{
int    n,k;
int    max_land;

cin >> n >> k;

if(n % 2)
max_land = (n / 2 + 1 + n / 2) * (n / 2) + n / 2 + 1;
else
max_land = n * n / 2;
if(max_land < k)
puts("NO");
else
{
puts("YES");
if(n % 2 == 0)
{
int    flag = 0;
int    count = 0;
for(int i = 0;i < n;i ++)
{
for(int j = 0;j < n;j ++)
if(count < k && (j + flag) % 2== 0)
{
cout << 'L';
count ++;
}
else
cout << 'S';
flag = !flag;
cout << endl;
}
}
else
{
int    flag = 0;
int    count = 0;
for(int i = 0;i < n;i ++)
{
for(int j = 0;j < n;j ++)
{
if(count < k && !flag && j % 2 == 0)
{
cout << 'L';
count ++;
}
else    if(count < k && flag && j % 2)
{
cout << 'L';
count ++;
}
else
cout << 'S';
}
flag = flag == 1 ? 0 : 1;
cout << endl;
}

}
}

return    0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: