【Codeforces 745 B Hongcow Solves A Puzzle】
来源:互联网 发布:淘宝考试虚拟类目下 编辑:程序博客网 时间:2024/05/16 14:18
B. Hongcow Solves A Puzzle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.
…..
…..
…..
题意 : 给出一张拼图,问两张完全一样的拼图,是否可以拼成矩形,’X’构成的拼图也为矩形
思路 : 拼图不可以旋转,矩形拼图的一半也为矩形,若符合矩形,者含有 ‘X’ 的行必须完全相同(似乎不严谨但是pass了=-=)
AC代码:
#include<bits/stdc++.h>using namespace std;char st[510][510],s[510];int main(){ int N,M; scanf("%d %d",&N,&M); for(int i = 0 ; i < N; i++) scanf("%s",st[i]); int ok = 1,k = 0; for(int i = 0 ; i < N; i++) for(int j = 0 ; j < M ; j++) if(st[i][j] == 'X'){ if(k == 0) k = 1,strcpy(s,st[i]); else if(strcmp(s,st[i]) != 0) ok = 0; } if(ok) printf("YES\n"); else printf("NO\n"); return 0;}
- CodeForces 745B Hongcow Solves A Puzzle
- 745 B. Hongcow Solves A Puzzle codeforces
- 【Codeforces 745 B Hongcow Solves A Puzzle】
- 【37.50%】【codeforces 745B】Hongcow Solves A Puzzle
- Hongcow Solves A Puzzle CodeForces
- Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle
- Codeforces Round #385 (Div. 2) 745B Hongcow Solves A Puzzle
- Codeforce#385B.Hongcow Solves A Puzzle
- Codeforces Round #385 (Div. 2) -- B. Hongcow Solves A Puzzle (判断是否是矩形,水题)
- Codeforces Round #385 (Div. 2)B. Hongcow Solves A Puzzle【思维+暴力】
- Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle 几何、思维题
- Hongcow Solves A Puzzle (思维)
- CodeForces745B B - Hongcow Solves A Puzzle 暴力+判断
- Codeforces 745C Hongcow Builds A Nation
- codeforces A. Orchestra B. Island Puzzle
- Codeforces 745B HongCow and puzzles 矩形(水)
- Hongcow Builds A Nation CodeForces
- 【26.42%】【codeforces 745C】Hongcow Builds A Nation
- [BZOJ3721]PA2014 Final Bazarek 单调性
- %00截断攻击的探索
- 技术层--必备数据知识(1):数据仓库之基本架构及ETL
- pat 1055. 集体照
- 技术层--必备数据知识(2):数据仓库之数据存储
- 【Codeforces 745 B Hongcow Solves A Puzzle】
- Cookie与Session的区别
- 高手病犯了~之打印图形1~
- 数据概论
- JS中为false的几种情况
- Action 类 中访问Webcontent目录下的文件
- 豆瓣热评电影爬取
- sklearn模型持久化
- ubuntu 安装 PHP+MySQL+Apache2环境