Marlin (思维)
The city of Fishtopia can be imagined as a grid of 44 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1)(1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4,n)(4,n). The second village is located at (4,1)(4,1) and its people love the Salmon pond at (1,n)(1,n).
The mayor of Fishtopia wants to place kk hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, nn and kk (3≤n≤993≤n≤99, 0≤k≤2×(n−2)0≤k≤2×(n−2)), nn is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 44 lines that describe the city, each line should have nn characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
如何去看这个题,可以把他看成关于对称的图形,上下对称和左右对称
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=3e5+5;
typedef long long ll;
using namespace std;
char Map[5][105];
int n,k;
void init()
{
for(int t=0;t<4;t++)
{
for(int j=0;j<n;j++)
{
Map[t][j]='.';
}
}
}
int main()
{
cin>>n>>k;
init();
if(k%2==0)
{
int s=k/2;
for(int t=1;t<s+1;t++)
{
Map[1][t]='#';
}
for(int t=1;t<s+1;t++)
{
Map[2][t]='#';
}
cout<<"YES"<<endl;
for(int t=0;t<4;t++)
{
puts(Map[t]);
}
}
else
{
int s=n/2;
Map[1][s]='#';
k--;
for(int t=1;t<n/2;t++)
{
if(k==0)
{
break;
}
else
{
Map[1][t]='#';
Map[1][n-1-t]='#';
k-=2;
}
}
for(int t=1;t<n/2;t++)
{
if(k==0)
{
break;
}
else
{
Map[2][t]='#';
Map[2][n-1-t]='#';
k-=2;
}
}
cout<<"YES"<<endl;
for(int t=0;t<4;t++)
{
puts(Map[t]);
}
}
return 0;
}
Marlin (思维)的更多相关文章
- CF980B Marlin 构造 思维 二十四
Marlin time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- 计算机程序的思维逻辑 (33) - Joda-Time
Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...
- 计算机程序的思维逻辑 (53) - 剖析Collections - 算法
之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
随机推荐
- opennebula 镜像池
{ "IMAGE_POOL": { "IMAGE": [ { ", ", ", "TEMPLATE": { & ...
- Django Rest Framework框架 ---- url控制器
Django Rest Framework框架 ---- url控制器
- eclipse——配置maven插件
Step 1 配置installations installations:指定Maven核心程序的位置 从本地磁盘中找到本地maven的位置 Step 2 配置user settings user ...
- 编写高质量代码改善C#程序的157个建议——建议24:迭代器应该是只读的
建议24:迭代器应该是只读的 如果注意观察会发现,FCL中的迭代器只有GetEnumerator方法,没有SetEnumerator方法,所有的集合类也没有一个可以写的迭代器属性.原因有二: 一:这违 ...
- 微软和Google的盈利模式对比分析
一: 微软和Google是世界上最成功科技巨头之一,但他们之间却有着不同的产品和业务,二者的盈利方式也各有不同,本文将分析和探讨的二者盈利模式的异同. 微软的盈利模式 在1975年由大学肄业的Bill ...
- 【C#】MVC+EF+LINQ 综合小项目
第一,创建数据库 create table category(id int primary key,name nvarchar(20)) create table news(id int primar ...
- web api 设置允许跨域,并设置预检请求时间
<httpProtocol> <customHeaders> <!--响应类型 (值为逗号分隔的一个字符串,表明服务器支持的所有跨域请求的方法)--> <ad ...
- opencv3.3.1+vs2015+c++实现直接在图像上画掩码,保存掩码图片
左键红右键蓝,保存为k #include "opencv2\imgproc\imgproc.hpp" // Gaussian Blur #include "opencv2 ...
- 修改Tomcat主目录
在默认安装后,tomcat的主目录是webapps/root目录,如果我们想改变tomcat的主目录的话可以这样做: 1 %TOMCAT_HOME%/webapps/下直接创建,这种方法有一个缺点,就 ...
- 强制json格式