Codeforces Round #480 (Div. 2): 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 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?

Input

The first line of input contain two integers, nn and kk (3n993≤n≤990k2×(n2)0≤k≤2×(n−2)), nn 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 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.

Examples
input
7 2
output
YES
.......
.#.....
.#.....
.......
input
5 3
output
YES
.....
.###.
.....
.....


题意:

给你一个4*n的点阵,你要往其中刚好k个点上放上障碍物('#'),要求放完之后从点(1,1)到(4,n)的最短路数量和从点(4,1)到(1,n)的最短路数量仍然相同,其中n一定为奇数,障碍物不能放在最外围,如果没有满足条件的方法输出NO,否则输出任意一种

扫描二维码关注公众号,回复: 907995 查看本文章

思路:

一定可以放,当k为偶数的时候从左往右两个两个放直到放完

当k为奇数的时候,先往最中间上方放一个,之后只要从左往右对称放就行了

拿AC代码运行一下一下就明白了


#include<stdio.h>
char str[6][108];
int main(void)
{
	int n, k, i, j;
	scanf("%d%d", &n, &k);
	for(i=1;i<=4;i++)
	{
		for(j=1;j<=n;j++)
			str[i][j] = '.';
	}
	if(k%2==0)
	{
		for(i=2;i<=n-1;i++)
		{
			if(k>=2)
			{
				k -= 2;
				str[2][i] = str[3][i] = '#';
			}
		}
	}
	else
	{
		k--;
		str[2][n/2+1] = '#';
		for(i=n/2;i>=2;i--)
		{
			if(k>=2)
			{
				str[2][i] = str[2][n-i+1] = '#';
				k -= 2;
			}
		}
		for(i=2;i<=n/2;i++)
		{
			if(k>=2)
			{
				str[3][i] = str[3][n-i+1] = '#';
				k -= 2;
			}
		}
	}
	printf("YES\n");
	for(i=1;i<=4;i++)
	{
		for(j=1;j<=n;j++)
			printf("%c", str[i][j]);
		puts("");
	}
	return 0;
}



猜你喜欢

转载自blog.csdn.net/jaihk662/article/details/80256067