日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【37.50%】【codeforces 745B】Hongcow Solves A Puzzle

發(fā)布時間:2025/4/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【37.50%】【codeforces 745B】Hongcow Solves A Puzzle 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Hongcow likes solving puzzles.

One day, Hongcow finds two identical puzzle pieces, with the instructions “make a rectangle” next to them. The pieces can be described by an n by m grid of characters, where the character ‘X’ denotes a part of the puzzle and ‘.’ denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.

The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.

You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two ‘X’ from different pieces can share the same position.

Input
The first line of input will contain two integers n and m (1?≤?n,?m?≤?500), the dimensions of the puzzle piece.

The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters ‘.’ and ‘X’ only. ‘X’ corresponds to a part of the puzzle piece, ‘.’ is an empty space.

It is guaranteed there is at least one ‘X’ character in the input and that the ‘X’ characters form a 4-connected region.

Output
Output “YES” if it is possible for Hongcow to make a rectangle. Output “NO” otherwise.

Examples
input
2 3
XXX
XXX
output
YES
input
2 2
.X
XX
output
NO
input
5 5
…..
..X..
…..
…..
…..
output
YES
Note
For the first sample, one example of a rectangle we can form is as follows

111222
111222
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.

In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:

…..
..XX.
…..
…..
…..

【題目鏈接】:http://codeforces.com/contest/745/problem/B

【題解】

題意有點(diǎn)迷;
大概是說那個所給的輸入組成的一個X聯(lián)通塊只能整體移動吧.
然后問你兩個這樣的聯(lián)通塊能不能組成一個長方形。
因?yàn)槭裁炊甲儾涣恕?
所以只要在輸入的那個圖里面判斷X是不是長方形就好了(中間不能有空的);
用bfs搞搞.

【完整代碼】

#include <iostream> #include <queue> #include <cstring> #include <cstdio>using namespace std;const int MAXN = 550; const int dx[5] = {0,0,0,1,-1}; const int dy[5] = {0,1,-1,0,0};int n,m,fz = 0,nq = 0; int a[MAXN][MAXN]; queue <pair<int,int> > dl;int main() {//freopen("F:\\rush.txt","r",stdin);memset(a,0,sizeof(a));cin >> n >> m;for (int i = 1;i <= n;i++){char key;for (int j = 1;j <=m;j++){cin >> key;if (key == 'X')a[i][j] = 1;elsea[i][j] = 0;}}for (int i = 1;i <= n;i++)for (int j = 1;j <= m;j++)if (a[i][j]==1){int minx=i,maxx=i,miny=j,maxy=j;a[i][j] = 0;int now = 1;dl.push(make_pair(i,j));while (!dl.empty()){int x = dl.front().first,y = dl.front().second;dl.pop();for (int p = 1;p <= 4;p++){int tx = x+dx[p],ty = y+dy[p];if (a[tx][ty]){now++;minx = min(minx,tx);maxx = max(maxx,tx);miny = min(miny,ty);maxy = max(maxy,ty);a[tx][ty] = 0;dl.push(make_pair(tx,ty));}}}int chang = maxy-miny+1;int kuan = maxx-minx+1;int total = chang*kuan;if (total == now){puts("YES");return 0;}else{puts("NO");return 0;}}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/AWCXV/p/7626802.html

總結(jié)

以上是生活随笔為你收集整理的【37.50%】【codeforces 745B】Hongcow Solves A Puzzle的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。