B - Sea and Islands
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 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
Input5 2OutputYES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSSInput5 25OutputNO
题意:给定n和k,求在n*n的矩阵中能否填出k座岛。(S表示海,L表示岛,上下左右相邻的L算作一个岛)。
水啊,只要不相邻就可以了。
附AC代码:
#include <iostream>
using namespace std; int main(){
int n,k;
cin>>n>>k;
if(n%== && k>(n/)*n || n%== && k>(n/+)*(n/+)+(n/)*(n/)){
cout<<"NO";
}
else{
cout<<"YES"<<endl;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(k> && (i+j)%==){
cout<<"L";
k--;
}
else{
cout<<"S";
}
}
cout<<endl;
}
}
}
B - Sea and Islands的更多相关文章
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- CF Sea and Islands
Sea and Islands time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- 544B. Sea and Islands
题目链接 题意: n*n的里面全是S的方格中,填充L,若填充的L上下左右都没有相邻的L则是一个快,问题是能否形成k个块 n可以去奇数也可以去偶数 只要我们输出满足条件的一个结果就好了 对于从0 - n ...
- [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter
Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...
- | dp-the Treasure Hunter
题目: A. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 mega ...
- Codeforces Round #302 解题报告
感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings You are given a string q. A sequence o ...
- Codeforces Round #302 (Div. 2)
A. Set of Strings 题意:能否把一个字符串划分为n段,且每段第一个字母都不相同? 思路:判断字符串中出现的字符种数,然后划分即可. #include<iostream> # ...
- 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 ...
随机推荐
- poj3211 Washing Clothes
Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...
- linux实现php定时执行cron任务详解(转)
对于PHP本身并没有一套解决方案来执行定时任务,不过是借助sleep函数完成的.这种方就是要提前做一些配置,如实现过程: 复制代码 代码如下: ignore_user_abort();//关掉浏览器, ...
- 在Livemedia的基础上开发自己的流媒体客户端 V 0.01
在Livemedia的基础上开发自己的流媒体客户端 V 0.01 桂堂东 xiaoguizi@gmail.com 2004-10 2004-12 友情申明: 本文档适合已经从事流媒体传输工作或者对网络 ...
- 2016/07/11 PHP接口的介绍与实现
接口定义了实现某种服务的一般规范,声明了所需的函数和常量,但不指定如何实现.之所以不给出实现的细节,是因为不同的实体可能需要用不同的方式来实现公共的方法定义.关键是要建立必须实现的一组一般原则 ...
- EasyDarwin开源流媒体云平台之云台ptz控制设计与实现
本文转自EasyDarwin开源团队成员Alex的博客:http://blog.csdn.net/cai6811376/article/details/51912692 近日,EasyDarwin云平 ...
- bootstrap-table 行内编辑
1.文件引入 <link rel="stylesheet" href="bootstrap.css"> <link rel="sty ...
- CSS的两种盒模型
盒模型一共有两种模式,一种是标准模式,另一种就是怪异模式. 当你用编辑器新建一个html页面的时候你一定会发现最顶上都会有一个DOCTYPE标签,例如: <!DOCTYPE HTML PUBLI ...
- JQuery 如何获取select选中的值
一.html代码 <select id="ddl"> <option value="100" emoney="12" &g ...
- ByteBuf(图解1)
目录 源码工程 写在前面 Netty ByteBuf 优势 手动获取与释放ByteBuf 自动获取和释放 ByteBuf 方式一:TailHandler 自动释放 方式二:SimpleChannelI ...
- opencv配置指南
今天配置了一把opencv,在vs2013,Python.IDEA(Java)上分别作了配置.总结成文档,分享给大家. 搭建opencv+vs2013的环境 安装opencv3.0 alpha 和 v ...