码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces544B:Sea and Islands

时间:2015-05-15 15:40:39      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:codeforces

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?≤?1000?≤?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

题意:在n*n的全是S矩阵里插入m块L,L的左右上下不相邻才算一块,如果有多个L通过上下左右能够连起来,它们算一块

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define LL long long
#define N 205
#define MOD 19999997
#define INF 0x3f3f3f3f
#define EXP 1e-8

const double Pi = acos(-1.0);

int main()
{
    int n,m,cnt,i,j;
    W(~scanf("%d%d",&n,&m))
    {
        if((n%2==0&&m*2<=n*n)||(n%2&&m*2<=n*n+1))
        {
            printf("YES\n");
            cnt = 0;
            UP(i,1,n)
            {
                UP(j,1,n)
                {
                    if(i%2==j%2 && cnt<m)
                    {
                        printf("L");
                        cnt++;
                    }
                    else
                        printf("S");
                }
                printf("\n");
            }
        }
        else
            printf("NO\n");
    }

    return 0;
}


Codeforces544B:Sea and Islands

标签:codeforces

原文地址:http://blog.csdn.net/libin56842/article/details/45743643

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!