Codeforces 980B 思维题

题目链接:http://codeforces.com/contest/980/problem/B

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

The city of Fishtopia can be imagined as a grid of 4

rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4,n). The second village is located at (4,1) and its people love the Salmon pond at (1,n)

.

The mayor of Fishtopia wants to place k

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, n

and k ( 3n99, 0k2×(n2)), n

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 4

lines that describe the city, each line should have n

characters, each of which is "#" if that cell has a hotel on it, or "." if not.

Examples
Input
Copy
7 2
Output
Copy
YES
.......
.#.....
.#.....
.......
Input
Copy
5 3
Output
Copy
YES
.....
.###.
.....
.....

题意:给你一个4 * N的矩阵(N一定是奇数),放K个障碍物,障碍物不能放边界, 要求从左上角走到右下角的最短路,和左下角走到右上角的最短路数目相同。

题解:构造相对对称矩阵即可。

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pb push_back()
#define sz(x) ((int)x.size())

char s[101][101];
int main()
{
    memset(s, '.', sizeof(s));
    int m, k;
    scanf("%d %d", &m, &k);
    puts("YES");
    if(k % 2 == 0) {
        int t = k / 2;
        for(int j = 1;j <= t;j ++) s[2][j+1] = '#';
        for(int j = 1;j <= t;j ++) s[3][j+1] = '#';
    } else {
        if(k <= m - 2) {
            s[3][m/2+1] = '#';
            k --;
            for(int j1 = m / 2, j2 = m / 2 + 2;k >= 2;k -= 2, j1 --, j2 ++) {
                s[3][j1] = '#';
                s[3][j2] = '#';
            }
        } else {
            for(int j = 2;j <= m - 1;j ++) s[2][j] = '#';
            k -= m - 2;
//            printf("%d\n", k);
            assert(k % 2 == 0);
            for(int j1 = m / 2, j2 = m / 2 + 2;k >= 2;k -= 2, j1 --, j2 ++) {
                s[3][j1] = '#';
                s[3][j2] = '#';
            }
        }
    }
    for(int i = 1;i <= 4;i ++) {
        for(int j = 1;j <=m;j ++) {
            printf("%c",s[i][j]);
        }
        puts("");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值