B. Sea and Islands

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/544/problem/B

Description

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 Input

5 2

Sample Output

YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS

HINT

题意

一个n*n的矩形,让你构造一个图形,有k个连通块

题解:

首先判断连通块最多的情况,就是10101这样子的,然后我每次消去一个阻碍,就会减少一个连通块,然后就这样搞搞搞就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int g[][];
int main()
{
int ans=;
int n=read(),k=read();
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if((i+j)%==)
{
g[i][j]=;
ans++;
}
else
g[i][j]=;
}
}
if(n%==)
ans++;
ans-=k;
if(ans<)
{
puts("NO");
return ;
}
puts("YES");
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(ans==)
break;
if(g[i][j]==)
{
g[i][j]=;
ans--;
}
}
if(ans==)
break;
} ans++;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(g[i][j])
printf("S");
else
printf("L");
}
printf("\n");
} }

Codeforces Round #302 (Div. 2) B. 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) C Writing Code

    题目传送门 /* 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][ ...

  3. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  4. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  5. Codeforces Round #302 (Div. 2)

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

  6. Codeforces Round #302 (Div. 1) C. Remembering Strings DP

    C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  7. Codeforces Round #302 (Div. 2) D - Destroying Roads 图论,最短路

    D - Destroying Roads Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544 ...

  8. Codeforces Round #302 (Div. 2) C. Writing Code 简单dp

    C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...

  9. Codeforces Round #302 (Div. 2) A. Set of Strings 水题

    A. Set of Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/pr ...

随机推荐

  1. 【Eclipse】Elipse自定义library库并导入项目

    1.定义像JRE System Library之类的库 (1)点击UserLibrary (2)如果没有就点击new新建一个user library,否则进行4  (3)向user library添加 ...

  2. Perl6多线程2: Promise new/keep/bread/status/result

    来源于个人理解的翻译. 创建一个 promise: my $p = Promise.new; 可以打印运行 的Promise 状态: my $p = Promise.new(); $p.then({s ...

  3. Linux下帮助命令

    帮助命令(各种命令区别)   最常用的帮助命令   help --help help cd 查看内置命令的使用 info man   help cd 查看内置命令的使用   获得帮助的途径:   ma ...

  4. offset宏的讲解【转】

    转自:http://blog.csdn.net/tigerjibo/article/details/8299584 1.offset宏讲解 #define offsetof(TYPE, MEMBER) ...

  5. Ubuntu命令设置ip网关dns

    本文系转载,介绍Ubuntu如何设置IP和网络来连接网络 如果是在虚拟机中使用Ubuntu,那么设置之前请先参照我的上一遍文章虚拟机Net方式设置连接外网中的网络设置部分,先设置好主机的网络,然后配置 ...

  6. Python3中字符串的编码与解码以及编码之间转换(decode、encode)

    一.编码 二.编码与解码 Python3中对py文件的默认编码是urf-8.但是字符串的编码是Unicode. 由于Unicode采用32位4个字节来表示一个字符,存储和传输太浪费资源,所以传输和存储 ...

  7. HDU 2594 Simpsons’ Hidden Talents(KMP求s1前缀和s2后缀相同部分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目大意:给两串字符串s1,s2,,找到最长子串满足既是s1的前缀又是s2的后缀,输出子串,及相 ...

  8. Java的Stack类实现List接口真的是个笑话吗

        今天在网上闲逛时看到了这样一个言论,说“Java的Stack类实现List接口的设计是个笑话”.   当然作者这篇文章的重点不是这个,原本我也只是一笑置之,然而看评论里居然还有人附和,说“Ja ...

  9. scala学习笔记3

    一.条件表达式 在scala中if/else表达式有值,这个值就是跟在if或者else之后的表达式的值. scala> val x = 10 x: Int = 10 scala> val ...

  10. 摄像机distortion vector、project matrix、camera matrix

    关于标定后图像如何校正:http://wiki.ros.org/image_pipeline/CameraInfo ros distortion vector 参数顺序:http://docs.ros ...