题目传送门
1 /*
2 题意:在n^n的海洋里是否有k块陆地
3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S
4 输出完k个L后,之后全部输出S:)
5 5 10 的例子可以是这样的:
6 LSLSL
7 SLSLS
8 LSLSL
9 SLSLS
10 SSSSS
11 */
12 #include <cstdio>
13 #include <cstring>
14 #include <algorithm>
15 #include <cmath>
16 #include <string>
17 using namespace std;
18
19 const int MAXN = 1e2 + 10;
20 const int INF = 0x3f3f3f3f;
21
22 int main(void) //Codeforces Round #302 (Div. 2) B Sea and Islands
23 {
24 freopen ("B.in", "r", stdin);
25
26 int n, k;
27 while (scanf ("%d%d", &n, &k) == 2)
28 {
29 int mx = n * n / 2;
30 if ((n*n) & 1) mx += 1;
31 if (k > mx) puts ("NO");
32 else
33 {
34 puts ("YES");
35 if (k == 0)
36 {
37 for (int i=1; i<=n; ++i)
38 {
39 for (int j=1; j<=n; ++j) printf ("%c", 'S');
40 puts ("");
41 }
42 }
43 else
44 {
45 int cnt = 0; bool flag = true;
46 for (int i=1; i<=n; ++i)
47 {
48 for (int j=1; j<=n; ++j)
49 {
50 if (flag) {printf ("%c", 'L'); ++cnt;}
51 else printf ("%c", 'S');
52 if (cnt == k) flag = false;
53 else flag = !flag;
54 }
55 if (n % 2 == 0 && cnt < k) flag = !flag;
56 puts ("");
57 }
58 }
59 }
60 }
61
62
63 return 0;
64 }
65
66 /*
67 YES
68 SSSSS
69 LLLLL
70 SSSSS
71 LLLLL
72 SSSSS
73 NO
74 */