codeforce 980B - Marlin(构造)
1 second
256 megabytes
standard input
standard output
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?
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.
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.
7 2
YES
.......
.#.....
.#.....
.......
5 3
YES
.....
.###.
.....
.....
这是一道天坑题,不存在NO的情况,都是YES;
所以如果K是偶数就先放左边,如果K是奇数就从中间开始放;
题意:
有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民的活动地点是(4,n);
有一个村庄在(4,1),村民的活动地点是(1,n);
现在要修建k个宾馆,不能修建在边界上,问能否给出一种安排方案使得两个村庄的村民到他们各自的活动地点的最短路的条数相等。
思路:
画了几个实例就应该知道,无论n和k是多少,都可以构建出合理的方案,所以全是YES。
如果k为偶数,那么就上下对称,这个比较好构造;当k为奇数,我采用的是首先把第二排从中间开始向两边填满,然后第三排则是从中间一格的两边开始填。
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<time.h>
#include<stack>
#include<queue>
#include<deque>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
char a[][];
int main()
{
int n,k;
cin>>n>>k;
cout<<"YES"<<endl;
if(k%==)
{
for(int i=;i<=k/+;i++)
{
a[][i]='#';
a[][i]='#';
}
}
else
{
if(k<=n-)
{
int p=n/+;
int l=,r=;
for(int i=;i<=k;i++)
{
if(i%==)
{
a[][p+r]='#';
r++;
}
else
{
a[][p-l]='#';
l++;
}
}
}
else
{
for(int i=;i<=n-;i++)
{
a[][i]='#';
}
k=k-n+;
int l=,r=;
for(int i=;i<=k;i++)
{
if(i%==)
{
a[][r]='#';
r++;
}
else
{
a[][n-l]='#';
l++;
}
}
}
}
for(int i=;i<=;i++)
{
for(int j=;j<=n;j++)
{
if(a[i][j]!='#') a[i][j]='.';
else s++;
cout<<a[i][j];
}
cout<<endl;
}
return ;
}
codeforce 980B - Marlin(构造)的更多相关文章
- CF980B Marlin 构造 思维 二十四
Marlin time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- codeforces 980B Marlin
题意: 有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民的活动地点是(4,n): 有一个村庄在(4,1),村民的活动地点是(1,n): 现在要修建k个宾馆,不能修建在边界上,问能否给出一种 ...
- codeforce 1311E. Construct the Binary Tree (构造,就是个模拟)
ACM思维题训练集合 You are given two integers n and d. You need to construct a rooted binary tree consisting ...
- 【构造】Codeforces Round #480 (Div. 2) B. Marlin
题意:给你一个4*n的网格,保证n为奇数,让你在其中放k个障碍物,不能放在边界的格子上,使得从左上角走到右下角的最短路的方案数,恰好等于从左下角走到右上角的最短路的方案数. k为偶数时,以纵向为对称轴 ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- 学习笔记:Maven构造版本号的方法解决浏览器缓存问题
需要解决的问题 在做WEB系统开发时,为了提高性能会利用浏览器的缓存功能,其实即使不显式的申明缓存,现代的浏览器都会对静态文件(js.css.图片之类)缓存.但也正因为这个问题导致一个问题,就是资源的 ...
- 一步步构造自己的vue2.0+webpack环境
前面vue2.0和webpack都已经有接触了些(vue.js入门,webpack入门之简单例子跑起来),现在开始学习如何构造自己的vue2.0+webpack环境. 1.首先新建一个目录vue-wk ...
- About 静态代码块,普通代码块,同步代码块,构造代码块和构造函数的纳闷
构造函数用于给对象进行初始化,是给与之对应的对象进行初始化,它具有针对性,函数中的一种.特点:1:该函数的名称和所在类的名称相同.2:不需要定义返回值类型.3:该函数没有具体的返回值.记住:所有对象创 ...
- Eos开发——构造查询条件
1.ajax 方式 var data = { orgid :orgid,year:year ,month: month,type:type,sortField:'sellEmpname' ,sortO ...
随机推荐
- RabbitMQ初体验
这里官方使用的Pom是4.0.2版本 <dependencies> <dependency> <groupId>com.rabbitmq</groupId&g ...
- MySQL安装配置教程
环境:Windows 7 旗舰版 64位MySQL版本:mysql-5.5.14-winx64MySQL下载地址:http://dev.mysql.com/downloads/installer/ 1 ...
- tracecaller.cs
#region Utility #if TRACE private const string Traceformat = "\"{0}\",\"{1:yyyy- ...
- 51nod 1326 奇妙的spfa+dp
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1326 1326 遥远的旅途 题目来源: TopCoder 基准时间限制: ...
- 条款24:如果所有的参数都需要类型转换,那么请为此采用non-member函数
首先还是下面这个class; class Rational{ public: Rational(, ); int numurator() const; int denominator() const; ...
- js 变量与属性的区别
在全局作用域下, 表明全局变量x,属性b,都是window的属性,因为在全局作用域下,浏览器默认会创建一个window对象. 说明变量x不能通过delete进行删除,但是属性y可以通过delete进行 ...
- opencv 边界确定函数
多边形逼近,用嘴贴切的多边形标识 void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool c ...
- Cloudera Manager (centos)安装详细介绍
文章全部来自:Cloudera Manager (centos)安装详细介绍http://www.aboutyun.com/thread-9190-1-1.html(出处: about云开发) 这里已 ...
- 使用Gson轻松解决复杂结构的Json数据解析
转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50961803 JSON简介 JSON(JavaScript Object Notati ...
- Dijkstra算法(带路径模板)
个人心得:Dijkstra算法是贪心思想的一种延伸,注意路径pre,pre数组表示此时最短路径中的前一个顶点.每次更新到目的点时更新: 从源点出发,更新路径,然后找出此时最短的点,然后以这个点为头,看 ...