题目链接

题意:

n*n的里面全是S的方格中,填充L,若填充的L上下左右都没有相邻的L则是一个快,问题是能否形成k个块

n可以去奇数也可以去偶数

只要我们输出满足条件的一个结果就好了

对于从0 - n-1的矩阵下标,横纵坐标之和对于上面的两个图

画下划线的是符合条件的块,并且每个块只含有一个L

只需要对下边和是偶数的位置值为L,就可以了。

n是奇数时候最多有 n*n/2+ 1 个块

n是偶数时候最多有 n*n 个块

Java程序:

import java.util.Scanner;

public class B544 {
static void run(){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int x= ((n*n)>>1);
// 奇数 + 1 个块
if(n%2==1) x++;
if(k>x){
System.out.println("NO");
return;
}
System.out.println("YES");
for(int i = 0 ;i<n;i++){
for(int j=0;j<n;j++){
// 偶数下标和 值为 L
if(k>0 &&(i+j)%2==0){
System.out.print("L");
k--;
}else
System.out.print("S");
}
System.out.println();
}
}
public static void main(String[] args){
run();
}
}

Python程序:

a,b=map(int,raw_input().split())
grid=[['S' for i in xrange(a)]for j in xrange(a)]
for i in xrange(a):
for j in xrange(a):
if i%2==j%2 and b:
b-=1
grid[i][j]='L'
if b:print 'NO'
else:
print 'YES'
for i in grid:print ''.join(i)

544B. Sea and Islands的更多相关文章

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

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  2. CF Sea and Islands

    Sea and Islands time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. 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 ...

  4. B - Sea and Islands

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A map ...

  5. Codeforces Round #302 解题报告

    感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings   You are given a string q. A sequence o ...

  6. [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter

    Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...

  7. | dp-the Treasure Hunter

    题目: A. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 mega ...

  8. Codeforces Round #302 (Div. 2)

    A. Set of Strings 题意:能否把一个字符串划分为n段,且每段第一个字母都不相同? 思路:判断字符串中出现的字符种数,然后划分即可. #include<iostream> # ...

  9. 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 ...

随机推荐

  1. iOS7 隐藏状态栏 hide statusBar

    1.调用 [self setNeedsStatusBarAppearanceUpdate]; 2.重载以下函数 - (BOOL)prefersStatusBarHidden{ return _hide ...

  2. 跨域访问-需要设置HTTP响应标头设置

    跨域访问-需要设置HTTP响应标头设置 前提:服务端网站的配置(被请求的网站) 1.需要在IIS服务器站点的功能视图中设置HTTP响应标头: 2.双击“HTTP响应标头”进入设置界面 3.点击右侧添加 ...

  3. com.Goods.ForEach

    com.Goods.ForEach(g => { g.TransactionPrice = getUnitPriceByProductId(g.ProductID); g.ExpressMone ...

  4. POC - ASP.NET & IIS 部分

    终于得到了我VM的管理员权限啦啦.接下来不需要把IIS架在我自己的电脑上了,将架在我的VM上. 1. 先添加ISAP和CGI的组件. 2. 将defaultAppPool的MODE设为CLASSIC, ...

  5. Matlab实现单(双)极性(不)归零码

    Matlab实现单(双)极性(不)归零码 内容大纲 Matlab实现单极性不归零波形(NRZ),0 1 幅值 Matlab实现单极性归零波形(RZ),0 1 幅值 Matlab实现双极性不归零波形,- ...

  6. 【Same Tree】cpp

    题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...

  7. Python 获取学校图书馆OAPC账号对应的身份证号码

    import urllib.request import urllib.parse import http.cookiejar import re lib_login = 'http://xxx.ed ...

  8. hibernate--联合主键(了解+,掌握-)

    如果一个表有多个主键(= =一般比较少) 8.4. 组件作为联合标识符(Components as composite identifiers) 先定义一个类OrderLineId (实现接口,imp ...

  9. ubuntu10.04编译内核不显示grub菜单解决

    问题描述:        ubuntu10.04 内核版本2.6.32.28编译内核之后版本2.6.37.6,系统在编译完内核之后,不显示grub菜单 参考资料:            http:// ...

  10. 生成中文版JavaDoc

    RT. 在用IDEA生成中文版JavaDoc时,出现如下问题: java.lang.IllegalArgumentException at sun.net.www.ParseUtil.decode(P ...