544B. Sea and Islands
题意:
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的更多相关文章
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- CF Sea and Islands
Sea and Islands time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- Codeforces Round #302 解题报告
感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings You are given a string q. A sequence o ...
- [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 (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 ...
随机推荐
- [转]ubuntu 10.04下的配置tftp服务器
[转]ubuntu 10.04下的配置tftp服务器 http://www.cnblogs.com/geneil/archive/2011/11/24/2261653.html 第1步:安装tftp所 ...
- verilog 学习笔记
1.在寄存器中: -1=1111 -2=1110 -3=1101 2.{1,0}=64‘H00000001_00000000;//默认是32位的位数-拼接: 3.defparam P1.Depth=1 ...
- [DHCP服务]——一个验证DHCP原理实验(VMware)
大致实验拓扑图 DHCP Server端的配置 1. 安装DHCP # yum -y install dhcp 2. 拷贝配置文件 # /dhcpd.conf.sample /etc/dhcp/dhc ...
- DataTemplate和ControlTemplate联系与区别
---恢复内容开始--- 正如标题中的两个拼接的单词所说,DataTemplate就是数据显示的模板,而ControlTemplate是控件自身的模板.(个人理解,错误请指出,谢谢) 我们看这二者在两 ...
- Week8 软件规格说明书
1.概述 本项目组所开发的软件为一个基于Android的手机端的时间管理软件,主要功能为时间管理软件,可以用于管理待办事项,记录一些需要提醒的信息等.有事件提醒.与Google账户同步.课程表等功能. ...
- ScrollView图片分页显示-简单
用到的控件: 1>UIScrollView:宽度和图片的宽度一样,因为分页的代码就一句 // 设置分页,这个分页的原理实际上是按照ScrollView的宽进行分页的,这里的图片的宽由于和Scro ...
- How to Build Android Applications Based on FFmpeg by An Example
This is a follow up post of the previous blog How to Build FFmpeg for Android. You can read the pre ...
- python 循环技巧
原文地址:http://docs.pythontab.com/python/python3.4/datastructures.html#tut-tuples 在字典中循环时,关键字和对应的值可以使用 ...
- Window.document对象(2)
四.操作样式 首先利用元素的ID找到该元素,存于一个变量中: var a = document.getElementById("id"): 然后可以对该元素的属性进行操作: a.s ...
- .NET Framework 4.5、4.5.1 和 4.5.2 中的新增功能
.NET Framework 4.5.4.5.1 和 4.5.2 中的新增功能 https://msdn.microsoft.com/zh-cn/library/ms171868.aspx