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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 745B】Hongcow Solves A Puzzle (思维,乱搞,字符串)

發布時間:2023/12/10 编程问答 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 745B】Hongcow Solves A Puzzle (思维,乱搞,字符串) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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. ..... ..... .....

題目大意:

? ? 判斷兩塊相同的有X的區域是否能拼成一個矩形。

解題報告:

? ?首先分析出,只有矩形才能拼成矩形,因此判斷給定的這個圖形是否是一個矩形即可

(ps:這是暑假集訓剛剛開始的組隊題目,當時這個題看起來還無從下手,比賽時ac這個題的人也不是很多,但是現在看來就是個規規矩矩的水題小case了,,,看來水平真的在長進呀,想起兩個月前迷茫的自己,我很開心。)

(ps:其實這應該不算個典型的字符串問題,,好吧都掛上了那就貼上這個標簽吧)

AC代碼:

#include<iostream> #include<cstring> #include<cstdio> using namespace std; char maze[501][501]; char ss[501];//模式空串 char ac[501];//模式匹配串 int main() {int n,m;int num=0;scanf("%d %d", &n, &m);for(int i = 0; i<m; i++) {ss[i]='.';}for(int i = 0; i<n; i++) {scanf("%s",&maze[i]);}int flag=0;for(int i = 0; i<n; i++) {if(flag==0) {if(!strcmp(ss,maze[i]) ) continue;flag=1;//代表這個串不是空串了 for(int j = 0; j<m; j++) {//代表這個串不是空串了 ac[j]=maze[i][j];if(maze[i][j]=='X') num++;}}else if(flag==1) {if(!strcmp(maze[i],ss) ) {printf("YES\n");return 0 ;}if(!strcmp(maze[i],ac) ) {continue;}if(strcmp(maze[i],ac) ) {printf("NO\n");return 0 ;}}}printf("YES\n");return 0 ; }

?

總結

以上是生活随笔為你收集整理的【CodeForces - 745B】Hongcow Solves A Puzzle (思维,乱搞,字符串)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。