codeforces 980B Marlin
题意:
有一个城市有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的更多相关文章
- codeforce 980B - Marlin(构造)
Marlin time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #480 (Div. 2) B. Marlin
题目地址:http://codeforces.com/contest/980/problem/B 官方题解: 题意: 有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民在(4,n)钓鱼:还有 ...
- 【构造】Codeforces Round #480 (Div. 2) B. Marlin
题意:给你一个4*n的网格,保证n为奇数,让你在其中放k个障碍物,不能放在边界的格子上,使得从左上角走到右下角的最短路的方案数,恰好等于从左下角走到右上角的最短路的方案数. k为偶数时,以纵向为对称轴 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- LeetCode 929 Unique Email Addresses 解题报告
题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...
- go不在dock显示运行
用这种方法就可以了go build -ldflags -H=windowsgui XXX.go
- HTML5 自定义属性
先声明 HTML5的自定义属性浏览器支持性不太好 目前只有firefox6+和chrome浏览器支持 元素除了自带的属性外 另外也可以加自定义属性 不过需要在前面加上data- 下面举个例子 ...
- system.out.printf()的使用方法
package com.lzc.test; public class Main { public static void main(String[] args) { // 定义一些变量,用来格式化输出 ...
- Python统计日志中每个IP出现次数
介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -* ...
- case关联表查询
select a.员工编号,b.`姓名`,b.`地址`,case when a.收入 is null then '没钱' when a.收入 < 2000 then '低收入'when a.收入 ...
- keycloak
keycloak报错, 少了配置项 keycloak.enabled=ture 找不到 publicKey, 1 ping不通 认证中心,2 网络不好
- 二叉树df
二叉树 最有搜索算法 打印偶节点 不要用递归
- mybatis test条件判断 如何引用 传入的 list参数中的map中的值
<select id="query" resultType="map"> select * from ${tbName} <where> ...
- js模拟链表
链表: 每个元素,都有一个指针,指向下一个元素 //链表 function LinkedList(){ var head = null; length = 0; this.append = funct ...