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 ;
}
CF Sea and Islands的更多相关文章
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- 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 ...
- B - Sea and Islands
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description A map ...
- 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 ...
随机推荐
- AWstat(linux下)
一.AWstat统计信息 AWstat是一个非常简洁而且功能强大的统计工具.它可以统计你站点的如下信息: 1 访问量.访问次数.页面浏览量.点击数.数据流量等精确到每月.每日.每小时 2 访问者国家. ...
- 高分辨率 2x图像: -webkit-min-device-pixel-ratio 的常见值对照
-webkit-min-device-pixel-ratio的常见值对照 原文地址:http://zhangyaochun.iteye.com/blog/1816582 前言: 本文来自于对 http ...
- PING的原理以及ICMP协议
主要内容: 1.ping的原理以及工作过程 2.ICMP协议 3.ICMP的应用:ping,traceroute 1.ping的原理以及工作过程 ping的原理 ping 程序是用来探测主机到主机 ...
- opennebula 出错截图与调试
- wikioi 1010 过河卒
题目描述 Description 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点 ...
- 会吓人的概念证明病毒: Chameleon
近期有这么一条新闻指出,有一对家长发现,黑客入侵了他们为10个月女儿所准备的婴儿监视器(baby monitor).该黑客除了远程操控该监视器的录像角度,还大声对着小孩喊叫.婴儿的爸爸冲进女儿房间后, ...
- UVA1099----Sharing Chocolate----在集合上的DP
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 关于OPenGL和OSG的矩阵 (转)
关于OPenGL和OSG的矩阵 矩阵真的是一个很神奇的数学工具, 虽然单纯从数学上看, 它并没有什么特别的意义, 但一旦用到空间中的坐标变换,它就“一遇风云便成龙”, 大显神威了.简单的工具实现了复杂 ...
- Android——ViewGroup的一个用法实例(转载)
找了很久,终于找到了. <?xml version="1.0" encoding="UTF-8" ?> <merge xmlns:androi ...
- 搭建一个全栈式的HTML5移动应用框架(纯干货,亲!)
打开HTML5的技术网站,满屏的“5个推荐的JavaScript框架”.“10个移动应用框架”,全都是你妹的框架, 但是,你知道这些框架是干毛用的吗?来吧,我们来梳理一下吧 目前HTML5涉及的框架大 ...