题意:

有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民的活动地点是(4,n);

有一个村庄在(4,1),村民的活动地点是(1,n);

现在要修建k个宾馆,不能修建在边界上,问能否给出一种安排方案使得两个村庄的村民到他们各自的活动地点的最短路的条数相等。

思路:

画了几个实例就应该知道,无论n和k是多少,都可以构建出合理的方案,所以全是YES。

如果k为偶数,那么就上下对称,这个比较好构造;当k为奇数,我采用的是首先把第二排从中间开始向两边填满,然后第三排则是从中间一格的两边开始填。

忽略了k为0的情况,导致n发wa和n发rte,惨!

代码:

 #include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
string a[];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
puts("YES");
for (int i = ;i < ;i++)
{
for (int j = ;j < n;j++) a[i].push_back('.');
}
if (k % == )
{
int c = ;
int l = ;
while ()
{
if (k <= ) break;
a[c][l] = '#';
c++;
k--;
if (k <= ) break;
if (c >= )
{
c = ;
l++;
}
}
}
else
{
int l = n / ,r = n / ;
int c = ;
while ()
{
if (k <= ) break;
a[c][l] = a[c][r] = '#';
if (l == r) k--;
else k-= ;
if (k <= ) break;
l--,r++;
if (l <= ) break;
}
l = n / - ,r = n / + ;
c = ;
while ()
{
if (k <= ) break;
a[c][l] = a[c][r] = '#';
k -= ;
l--,r++;
}
}
for (int i = ;i < ;i++) cout << a[i] << endl;
return ;
}

codeforces 980B Marlin的更多相关文章

  1. codeforce 980B - Marlin(构造)

    Marlin time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  2. Codeforces Round #480 (Div. 2) B. Marlin

    题目地址:http://codeforces.com/contest/980/problem/B 官方题解: 题意: 有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民在(4,n)钓鱼:还有 ...

  3. 【构造】Codeforces Round #480 (Div. 2) B. Marlin

    题意:给你一个4*n的网格,保证n为奇数,让你在其中放k个障碍物,不能放在边界的格子上,使得从左上角走到右下角的最短路的方案数,恰好等于从左下角走到右上角的最短路的方案数. k为偶数时,以纵向为对称轴 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. navicat连接oracle失败

    正常是成功的,失败的话,就是oci.dll的问题 在这边下载: https://www.oracle.com/technetwork/topics/winsoft-085727.html 然后找到对应 ...

  2. Java+selenium 如何定位下拉框select

    场景:需要进行下拉选择定位元素.   一.select菜单       select也是比较常见的,selenium封装了以下方法, 创建select WebElement selector = dr ...

  3. 运行python文件时出错SyntaxError: Non-UTF-8 code starting with '\xb5' in file, but no encoding declared;

    今天ytkah在运行python文件时出现错误,提示如下,很明显这是没有定义python文件编码引起的问题,那么要怎么解决呢?很简单,在文件头部定义一下就可以了. File "hello.p ...

  4. sed 操作命令

    sed介绍 grep 只能过滤文件内容,sed既能过滤文件内容同时还能对文件内容进行修改.  sed 算是一种编程语言,它有自己的固定语法. sed是一种行编辑器,sed会在内存中开辟一块独立的空间( ...

  5. [php] 索引数组合并选择两数组相加

    header("Content-Type:text/html;charset=utf-8");$arr1= Array ( 0 => Array ( 'pic' => ...

  6. mybatis {arg0} 与 {0}

    解决方案: MyBatis的XML的配置文件中声明设置属性的useActualParamName参数值为假 <setting name="useActualParamName" ...

  7. solr创建业务域以及指定中文分析器IK

    第一步:把中文分析器添加到工程中. 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下 ...

  8. [LeetCode] 709. To Lower Case_Easy

    Implement function ToLowerCase() that has a string parameter str, and returns the same string in low ...

  9. vue使用md5加密

    import crypto from 'crypto' export default { name: 'HelloWorld', data () { return { msg: 'Welcome to ...

  10. HttpwebRequest - 带ViewState的网页POST请求

    这是我今天下午碰到的案例,一个退订页面的post请求,请求头信息都很明确,but看看下面这个请求体,除了最后一个key是我的页面控件名称,其他的几个ViewState相关都是what呢?(ViewSt ...