构造 Codeforces Round #302 (Div. 2) B Sea and Islands

题目传送门

 /*
题意:在n^n的海洋里是否有k块陆地
构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S
输出完k个L后,之后全部输出S:)
5 10 的例子可以是这样的:
LSLSL
SLSLS
LSLSL
SLSLS
SSSSS
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std; const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f; int main(void) //Codeforces Round #302 (Div. 2) B Sea and Islands
{
freopen ("B.in", "r", stdin); int n, k;
while (scanf ("%d%d", &n, &k) == )
{
int mx = n * n / ;
if ((n*n) & ) mx += ;
if (k > mx) puts ("NO");
else
{
puts ("YES");
if (k == )
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j) printf ("%c", 'S');
puts ("");
}
}
else
{
int cnt = ; bool flag = true;
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
if (flag) {printf ("%c", 'L'); ++cnt;}
else printf ("%c", 'S');
if (cnt == k) flag = false;
else flag = !flag;
}
if (n % == && cnt < k) flag = !flag;
puts ("");
}
}
}
} return ;
} /*
YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS
NO
*/
上一篇:app配置智能硬件的解决方案


下一篇:python之花瓣美女下载