980B Marlin

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
Copy
7 2
output
Copy
YES
.......
.#.....
.#.....
.......
input
Copy
5 3
output
Copy
YES
.....
.###.
.....
.....


题意:输入n,k,一个4行n列的城市(矩阵),让你放置k个宾馆,有两个村庄,第一个村庄(1,1)要去(4,n)捕鱼,第二个村庄(4,1)要去(1,n)捕鱼,问怎么放置宾馆,才能让两个村庄的最短路线的个数相同,然后输出YES,打印出,4行n列的放置情况宾馆不能放置在边界上,' .'表示路,#表示宾馆,如果不可能就输出NO。然而我想说对的是这个题,还是不好懂的,昨晚比赛的时候,群里讨论都在那里跟题意较真,然后过了的大佬说是构造题。我们开始构造,构造了就wa 1,难适应我就想改了,电脑也没电了,就没做了,我能说CF开题,能不开在23点么,寝室断电23点,电脑只能坚持一个多小时点....刚开始我是从非边界第一个开始放置宾馆的,结果wa 1,群里问其他人,有几个和我情况一样,同样再问。。。这道题当时还是卡了很多人的...


题解:构造   对k的奇偶性讨论,奇数的时候就一行一行的放置宾馆,并且要从中间开始放,k为偶数的时候就一列一列的放置宾馆...

#include<bits/stdc++.h>
using namespace std;
char s[10][110];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0; i<4; i++)
        for(int j=0; j<n; j++)
            s[i][j]='.';
    if(k&1)
    {
        s[1][n/2]='#',k--;///先在中间放置一个宾馆
        for(int i=0; i<4; i++)
            for(int j=0; j<n/2; j++)
                if(i&&j&&k)
                    s[i][j]='#',s[i][n-j-1]='#',k-=2;然后一左一右放置
    }
    else
    {
        for(int i=0; i<4; i++)///三层循环一列一列的放置。
            for(int j=0; j<n; j++)
                for(int l=0; l<3; l++)
                    if(i&&j&&l&&k)
                        s[l][j]='#',k--;
    }
    puts("YES");
    for(int i=0; i<4; i++)
        cout<<s[i]<<endl;
    return 0;
}



猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80258878