CF Sea and Islands
1 second
256 megabytes
standard input
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.
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.
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.
5 2
YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS
5 25
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 ;
}
最新文章
- angular的$filter服务
- 图像相似度算法的C#实现及测评
- Android 设置闹铃步骤和基础代码
- C#中调用API
- SQL语句操作文件
- [转]iOS开发使用半透明模糊效果方法整理
- css 溢出文本显示省略号
- Hibernate 、多表关联映射-多对一关系(many-to-one)
- python--字符串操作(删除,替换)
- 【Spring 核心】AOP 面向切面编程
- 爬取西刺网代理ip,并把其存放mysql数据库
- UNIX网络编程——客户/服务器程序设计示范(八)
- uGUI使用代码动态添加Button.OnClick()事件(Unity3D开发之十二)
- [物理学与PDEs]第1章第6节 电磁场的标势与矢势 6.3 例 --- 电偶极辐射
- vue-08-axios-get-post-跨域
- ASP.NET Web API 启用跨域访问
- 动态设置和访问cxgrid列的Properties
- indy10的idhttpServer应答字符串
- numpy中的广播(Broadcasting)
- springcloud16---zuul-filter
热门文章
- 集成Jenkins Notifier for Chrome到Jenkins CI
- sql 自连接
- CentOS 使用yum命令安装出现错误提示&rdquo;could not retrieve mirrorlist http://mirrorlist.centos.org ***&rdquo;
- MyEclipse卡死解决
- python中使用list作为默认参数且调用时不给其赋值的问题
- 使用visual studio 2013 快速搭建phonegap开发环境
- PS-文字如何竖排版
- Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心
- 使用openssl工具生成证书
- HANDLER命令与实现