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?
The first line of input contain two integers, nn and kk (3≤n≤993≤n≤99, 0≤k≤2×(n−2)0≤k≤2×(n−2)), nn 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 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.
7 2
YES
.......
.#.....
.#.....
.......
5 3
YES
.....
.###.
.....
.....
这是一道天坑题,不存在NO的情况,都是YES;
所以如果K是偶数就先放左边,如果K是奇数就从中间开始放;
题意:
有一个城市有4行n列,n是奇数,有一个村庄在(1,1),村民的活动地点是(4,n);
有一个村庄在(4,1),村民的活动地点是(1,n);
现在要修建k个宾馆,不能修建在边界上,问能否给出一种安排方案使得两个村庄的村民到他们各自的活动地点的最短路的条数相等。
思路:
画了几个实例就应该知道,无论n和k是多少,都可以构建出合理的方案,所以全是YES。
如果k为偶数,那么就上下对称,这个比较好构造;当k为奇数,我采用的是首先把第二排从中间开始向两边填满,然后第三排则是从中间一格的两边开始填。
#include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<stdio.h> #include<cstdio> #include<time.h> #include<stack> #include<queue> #include<deque> #define inf 0x3f3f3f3f #define ll long long using namespace std; char a[5][105]; int main() { int n,k; cin>>n>>k; cout<<"YES"<<endl; if(k%2==0) { for(int i=2;i<=k/2+1;i++) { a[2][i]='#'; a[3][i]='#'; } } else { if(k<=n-2) { int p=n/2+1; int l=1,r=0; for(int i=1;i<=k;i++) { if(i%2==1) { a[2][p+r]='#'; r++; } else { a[2][p-l]='#'; l++; } } } else { for(int i=2;i<=n-1;i++) { a[2][i]='#'; } k=k-n+2; int l=1,r=2; for(int i=1;i<=k;i++) { if(i%2==1) { a[3][r]='#'; r++; } else { a[3][n-l]='#'; l++; } } } } for(int i=1;i<=4;i++) { for(int j=1;j<=n;j++) { if(a[i][j]!='#') a[i][j]='.'; else s++; cout<<a[i][j]; } cout<<endl; } return 0; }