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 nk (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 % )
max_land = (n / + + n / ) * (n / ) + n / + ;
else
max_land = n * n / ;
if(max_land < k)
puts("NO");
else
{
puts("YES");
if(n % == )
{
int flag = ;
int count = ;
for(int i = ;i < n;i ++)
{
for(int j = ;j < n;j ++)
if(count < k && (j + flag) % == )
{
cout << 'L';
count ++;
}
else
cout << 'S';
flag = !flag;
cout << endl;
}
}
else
{
int flag = ;
int count = ;
for(int i = ;i < n;i ++)
{
for(int j = ;j < n;j ++)
{
if(count < k && !flag && j % == )
{
cout << 'L';
count ++;
}
else if(count < k && flag && j % )
{
cout << 'L';
count ++;
}
else
cout << 'S';
}
flag = flag == ? : ;
cout << endl;
} }
} return ;
}

CF Sea and Islands的更多相关文章

  1. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  2. Codeforces Round #302 (Div. 2) B. Sea and Islands 构造

    B. Sea and Islands Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/p ...

  3. B - Sea and Islands

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A map ...

  4. 544B. Sea and Islands

    题目链接 题意: n*n的里面全是S的方格中,填充L,若填充的L上下左右都没有相邻的L则是一个快,问题是能否形成k个块 n可以去奇数也可以去偶数 只要我们输出满足条件的一个结果就好了 对于从0 - n ...

  5. [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter

    Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...

  6. | dp-the Treasure Hunter

    题目: A. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 mega ...

  7. Codeforces Round #302 解题报告

    感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings   You are given a string q. A sequence o ...

  8. Codeforces Round #302 (Div. 2)

    A. Set of Strings 题意:能否把一个字符串划分为n段,且每段第一个字母都不相同? 思路:判断字符串中出现的字符种数,然后划分即可. #include<iostream> # ...

  9. codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)

    题目链接: C. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 me ...

随机推荐

  1. NBearV3中文教程总目录

    1.NBearV3 Step by Step教程——ORM篇 摘要:本教程演示如何基于NBearV3的ORM模块开发一个Web应用程序的全过程.本教程演示的实体关系包括:继承.1对1关联.1对多关联, ...

  2. MFC中关于子对话框中编辑框不能编辑的问题

    最近在用MFC写程序.发现子对话框中的编辑框不能编辑.具体问题是这样的: 我有一个对话框YhglDlg,创建了这个对话框的子对话框ZjyhxxDlg,子对话框的Style属性为Child,Border ...

  3. eclipse提示servlet不存在 的解决办法

    在以前的版本中,Tomcat的common/lib目录下有一个名为servlet-api.jar的包,把它拷贝至你的java安装目录下jre/lib/ext下就可以了. 如果是:tomcat6就在To ...

  4. Error loading: \Java\jdk1.6.0_35\jre\bin\server\jvm.dll

    先看看错误:complie: [exec] Error loading: D:\Program Files\Java\jdk1.6.0_35\jre\bin\server\jvm.dll [exec] ...

  5. C++ 迭代器类别

    1.output迭代器:一次一步,只能向前,流水线上放着一批空的盒子,每次向前移动一个,往盒子里面塞一个东西. 2.input迭代器:一次一步,只能向前,流水线上放着一批零件,每次向前移动一个,可以看 ...

  6. MyReport:DataGrid的打印和打印预览

    本文说明怎样使用MyReport来实现Flex DataGrid组件的自己主动化打印预览和打印功能. 实现代码 <? xmlversion="1.0" encoding=&q ...

  7. 当调用List Remove 失效时 [C#] .

    有没有试过从一个集合里面移除一个对象之后,这个集合仍然留有这个对象?世界之大,无奇不有.稍有疏忽,便会导致这种奇怪的现象.现在让我们看看这个“不死”对象究竟是怎么一回事. 1.“不死”对象现身 这个问 ...

  8. 基于Raft构建弹性伸缩的存储系统的一些实践

    基于Raft构建弹性伸缩的存储系统的一些实践 原创 2016-07-18 黄东旭 聊聊架构 最近几年来,越来越多的文章介绍了 Raft 或者 Paxos 这样的分布式一致性算法,但主要集中在算法细节和 ...

  9. Win7 IE故障:APPCRASH,d3d9.dll,c0000005

    问题:        今天使用使用IE登录某网址,发现总是报错,如下图,无法浏览.         解决方案:       主要讲IE的呈现方案修改即可,如下步骤:       在IE的[Intern ...

  10. (LeetCode 135) Candy N个孩子站成一排,给每个人设定一个权重

    原文:http://www.cnblogs.com/AndyJee/p/4483043.html There are N children standing in a line. Each child ...