• B


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

    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 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 Input

    Input
    5 2
    Output
    YES
    SSSSS
    LLLLL
    SSSSS
    LLLLL
    SSSSS
    Input
    5 25
    Output
    NO

    题意:给定n和k,求在n*n的矩阵中能否填出k座岛。(S表示海,L表示岛,上下左右相邻的L算作一个岛)。

    水啊,只要不相邻就可以了。

    附AC代码:

    #include <iostream>
    using namespace std;
    
    int main(){
        int n,k;
        cin>>n>>k;
        if(n%2==0 && k>(n/2)*n || n%2==1 && k>(n/2+1)*(n/2+1)+(n/2)*(n/2)){
            cout<<"NO";
        }
        else{
            cout<<"YES"<<endl;
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(k>0 && (i+j)%2==0){
                        cout<<"L";
                        k--;
                    }
                    else{
                        cout<<"S";
                    }
                }
                cout<<endl;
            }
        }
    }
  • 相关阅读:
    vue-cli项目中使用vw——相比flexible更原生的移动端解决方案
    android shap画圆(空心圆、实心圆)
    Android四大组件——Activity跳转动画、淡出淡入、滑出滑入、自定义退出进入
    HDU 3980 Paint Chain (sg函数)
    HDU 3951 Coin Game (简单博弈)
    HDU 1850 Being a Good Boy in Spring Festival (Nim博弈)
    HDU 3389 Game (阶梯博弈)
    HDU 3032 Nim or not Nim? (sg函数)
    HDU 1907 John (Nim博弈)
    HDU 4638 Group (线段树 | 树状数组 + 离线处理)
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5705379.html
Copyright © 2020-2023  润新知