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 ...
随机推荐
- angularjs实现星星评分
angularjs实现星星评分 自定义指令 app.directive('myStars', function () { return { require : '?ngModel', // ?ngMo ...
- 用WebClient在异步下载或上传时每次只进行一个任务 C#
当在每次上传或者下载的时候,我只想进行一个任务的,我用的是WebClient类,但是我又不想用同步的方法UploadFile.DownloadFile,因为WebClient这个类的同步方法没有Upl ...
- 计算从哪天起应该购买预售火车票.cs
代码直接CSC编译即可. 计算从哪天起应该购买预售火车票.cs using System; using System.Diagnostics; using System.IO; class Progr ...
- python面向对象编程 继承 组合 接口和抽象类
1.类是用来描述某一类的事物,类的对象就是这一类事物中的一个个体.是事物就要有属性,属性分为 1:数据属性:就是变量 2:函数属性:就是函数,在面向对象里通常称为方法 注意:类和对象均用点来访问自己的 ...
- Android中轻松使用线程
当你第一次启动一个Android程序的时候,一个被 称为"main"的线程就被自动创建了.它被称为主线程或者UI线程,它是非常重要的因为负责分发事件给对应的widget,还包含画 ...
- 对servlet的 再总结 (精品)
首先 可以通过URL 在浏览器端访问servlet,因为在web.xml中配置了URL与类全名的 映射. 我们初学时,很容易分不清,浏览器端访问的 是jsp页面还是servlet. 其实当我们用浏览 ...
- 边缘检测︱基于 HED网络TensorFlow 和 OpenCV 实现图片边缘检测
本文摘录自<手机端运行卷积神经网络的一次实践 – 基于 TensorFlow 和 OpenCV 实现文档检测功能> 只截取感兴趣 的片段. . 一.边缘检测 1.传统边缘检测 Google ...
- Matlab批量读取文件夹文件
现在有一个文件夹 里面有50个左右的txt文件 每个文件大概三万行 两列 第一列是字符串 第二列是浮点数字 我只需要读第二列 现在我想写一个.M文件 批量读取这个文件夹里的txt文件 读取完以后的数组 ...
- 微信小程序如何在使用wx.request使用cookie
我主要是做asp.net mvc后端开发的,经常使用Jquery的ajax与后台的Web API进行数据交互. 最近公司要做一个小程序,要实现小程序与Web前端的通信,当然小程序是可以实现socket ...
- [EMWIN]FRAMEWIN 与 WINDOW 的使用注意
1.对于window控件,选中这类型控件的时候直接选中对应句柄即可: WM_InvalidateWindow(hWin); WM_SelectWindow(hWin); WM_CreateTimer( ...