CF980B Marlin 構造 思維 二十四
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
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?
InputThe 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.
Examples input Copy7 2output Copy
YESinput Copy
.......
.#.....
.#.....
.......
5 3output Copy
YES
.....
.###.
.....
.....
題意: 現在有一個4*n的地圖,a村莊的人在(1,1),他們要去(4,n),b村莊的人在(4,1),他們要去(1,n),路途的中間有m個酒店,村民不能經過酒店。問怎麽設置酒店可以使a、b村莊的人到目的地的最短路大小相同。
題解:通過一番枚舉驗證,發現只要酒店能關於x軸或者y軸對稱,就能滿足條件。
然後對比樣例,我們不難發現,m使偶數關於x軸對稱,為奇數關於y軸對稱。
接下來就是按照上面說的構造這樣的一個4*n的地圖,構造奇數的情況的時候小心一點就行。
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <iostream> #include <algorithm> #define debug(a) cout << #a << " " << a << endl using namespace std; const int maxn = 1e2 + 10; const int mod = 1e9 + 7; typedef long long ll; char mapn[maxn][maxn]; int main(){ std::ios::sync_with_stdio(false); ll n, m; cin >> n >> m; cout << "YES" << endl; for( ll i = 1; i <= 4; i ++ ) { for( ll j = 1; j <= n; j ++ ) { mapn[i][j] = ‘.‘; } } if( m % 2 == 0 ) { for( ll i = 2; i <= 3; i ++ ) { for( ll j = 2; j <= 1+m/2; j ++ ) { mapn[i][j] = ‘#‘; } } } else { ll t = ( n+1 ) / 2, num = m; //奇數對稱的中心點縱坐標是t,num不大於1時不用再填充了,大於1時關於t對稱填充 for( ll i = 2; i <= ( (m-1) / (n-2) ) + 2 && num > 1; i ++ ) { for( ll j = 1; j <= t-2 && num > 1; j ++ ) { mapn[i][t-j] = mapn[i][t+j] = ‘#‘; num -= 2; } } mapn[2][t] = ‘#‘; } for( ll i = 1; i <= 4; i ++ ) { for( ll j = 1; j <= n; j ++ ) { cout << mapn[i][j]; } cout << endl; } return 0; }
CF980B Marlin 構造 思維 二十四