题目链接:http://codeforces.com/contest/980/problem/B
The city of Fishtopia can be imagined as a grid of 4
.
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?
The first line of input contain two integers, n
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 4
题意:给你一个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;
}