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,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
随机推荐
- 面试题:servlet jsp cook session 背1
一.Servlet是什么?JSP是什么?它们的联系与区别是什么? Servlet是Java编写的运行在Servlet容器的服务端程序,狭义的Servlet是指Servlet接口,广义的Servlet是 ...
- rpmbuild SPEC语法
rpmbuild SPEC语法 摘自:http://bbs.chinaunix.net/thread-4179207-1-1.html spec文件写作规范 2008-09-28 11:52:17 分 ...
- 高级软件测试技术(测试管理工具实践day3)
昨天在晚上由于安装bugzilla中有一些小问题,并且需要手工安装很多perl模块 ppm install XXX(模块名称).一直到过了十二点就没有继续更博了.所以由今天更. 继昨天的安装问题之后 ...
- (转)XSS危害——session劫持
原文地址:http://www.cnblogs.com/dolphinX/p/3403027.html 在跨站脚本攻击XSS中简单介绍了XSS的原理及一个利用XSS盗取存在cookie中用户名和密码的 ...
- POJ3020 Antenna Placement(二分图最小路径覆盖)
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...
- MVC Action控制方式
1.Controller 的OnActionExecuting中控制 protected override void OnActionExecuting(ActionExecutingContext ...
- linux系统下ipmitool添加BMC帐号密码
需求:已知BMC帐号id2为root管理员帐号,添加id5bmc帐号 工具:ipmitool version 1.8.14 系统:CentOS release 6.6 (Final) 1,通过yum安 ...
- WP REST API: 设置和使用OAuth 1.0a Authentication(原文)
In the previous part of the series, we set up basic HTTP authentication on the server by installing ...
- C# 中请使用Contains判断字符串是否包含另一段字符串
∵ :使用Contains 比 IndexOf 的性能要高很多. 因为 Contains 是判断某个字符串是否在该字符串里面,而IndexOf是返回对应下标值 但是在使用contains的时候,注意转 ...
- CentOS 6.3下Samba服务器的安装与配置【转载】
本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.h ...