Codeforces Round #302 (Div. 2) B. Sea and Islands 构造
2015-05-08 12:25
423 查看
B. Sea and Islands
Time Limit: 20 Sec Memory Limit: 256 MB题目连接
http://codeforces.com/contest/544/problem/BDescription
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
5 2Sample Output
YESSSSSS
LLLLL
SSSSS
LLLLL
SSSSS
HINT
[b]题意 [/b]一个n*n的矩形,让你构造一个图形,有k个连通块
[b]题解:
[/b]
首先判断连通块最多的情况,就是10101这样子的,然后我每次消去一个阻碍,就会减少一个连通块,然后就这样搞搞搞就好了
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 1000001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; /* inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } */ inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int g[400][400]; int main() { int ans=0; int n=read(),k=read(); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if((i+j)%2==1) { g[i][j]=1; ans++; } else g[i][j]=0; } } if(n%2==1) ans++; ans-=k; if(ans<0) { puts("NO"); return 0; } puts("YES"); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(ans==0) break; if(g[i][j]==0) { g[i][j]=1; ans--; } } if(ans==0) break; } ans++; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(g[i][j]) printf("S"); else printf("L"); } printf("\n"); } }
相关文章推荐
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- codeforces-544B-Sea and Islands【构造】
- Codeforces Round #302 (Div. 2) B. Sea and Islands
- Codeforces Round #302(Div. 2)——B—— Sea and Islands
- Codeforces 544B - Sea and Islands(构造)
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle —— 构造 + 贪心
- 【VK Cup 2016 - Round 1 (Div 2 Edition)C】【构造】Bear and Forgotten Tree 3 构造一棵树直径为d且点1的深度为h
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造,思路)
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造 坐标离散化
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples(构造题,想法题,好题)
- VK Cup 2016 - Round 1 (Div. 2 Edition)-C - Bear and Forgotten Tree 3-构造
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #381 (Div. 2)C. Alyona and mex(构造题,好题)
- Codeforces Round #372 (Div. 2) C. Plus and Square Root —— 构造(数学题)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces544B:Sea and Islands