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

【题解】

题意有点迷;
大概是说那个所给的输入组成的一个X联通块只能整体移动吧.
然后问你两个这样的联通块能不能组成一个长方形。
因为什么都变不了。
所以只要在输入的那个图里面判断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;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626802.html

【37.50%】【codeforces 745B】Hongcow Solves A Puzzle相关推荐

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

    题干: Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the inst ...

  2. 【21.37%】【codeforces 579D】Or Game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【Codeforces】【161Div2】

    [题目来源]http://www.codeforces.com/contest/263 [A. Beautiful Matrix] [解析]模拟即可.按照题目的意思,找到1所在的位置(x, y),然后 ...

  4. 50道JAVA基础算法编程题【内含分析、程序答案】【建议收藏】【建议收藏】【建议收藏】

    非常基础的题目,但是想学好Java它真的是基础,基础有多重要我就不再废话,重要的事情说三遍[建议收藏][建议收藏][建议收藏]. [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一 ...

  5. Linux最常用命令50条【呕心沥血呐,望用之取之】

    Linux常用命令大全 第一章 Linux基础命令 [1]linux->ls [2]linux->alias [3]linux->cd [4]linux->clear [5]l ...

  6. (实验37)单片机,STM32F4学习笔记,代码讲解【内存管理实验】【正点原子】【原创】

    文章目录 其它文章链接,独家吐血整理 实验现象 主程序 内存池初始化程序 代码讲解 其它文章链接,独家吐血整理 (实验3)单片机,STM32F4学习笔记,代码讲解[按键输入实验][正点原子][原创] ...

  7. (实验50)单片机,STM32F4学习笔记,代码讲解【串口IAP实验】【正点原子】【原创】

    文章目录 ❤2023重新理解记录 其它文章链接,独家吐血整理 实验现象 主程序 IAP初始化程序 代码讲解 文章目录 ❤2023重新理解记录 其它文章链接,独家吐血整理 实验现象 主程序 IAP初始化 ...

  8. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  9. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

最新文章

  1. 2019年了,中文分词到底该怎么做?中文分词十年方法大盘点(附下载)
  2. 每周一书《Oracle 12 c PL(SQL)程序设计终极指南》
  3. MongoDB numa系列问题一:[initandlisten] connection refused because too many open connections:
  4. 谁说双非本科就一定无缘阿里?H哥粉丝刚刚6面通过,喜得Offer!
  5. 百度地图api 去左下角百度地图logo的方法
  6. Kibana Guide ( Kibana 向导 )
  7. 计算机应用基础多媒体应用试题,计算机等级考试:计算机应用基础复习题
  8. 请使用C#的文件流来拷贝文件
  9. CDH6离线安装教程
  10. matlab 交换两列数据,在MATLAB单元阵列的两列中列出单元格内容(List cell contents in two columns of MATLAB cell array)...
  11. 实时调度论文中经常出现的术语 ties broken arbitrary的意思
  12. “砍价”技巧受用终生
  13. 独立站引流技巧和营销思路
  14. 冒泡排序及其时间、空间复杂度解析
  15. Linux proxy 设置
  16. 4-Elasticsearch字段类型
  17. 粪菌移植构建人源化菌群小鼠的分析探讨
  18. Simpsons’ Hidden Talents(KMP ,两个串的前后缀匹配)
  19. 1109 擅长C – PAT乙级真题
  20. 迅雷下载原理的源代码(linux c)

热门文章

  1. BBC News 2012-02-07
  2. 严重: Dispatcher initialization failed java.lang.RuntimeException
  3. 关于程序员30/35岁以后就写不了代码(没前途)的问题。
  4. htmlparser解析网站时服务器返回的文件编码和页面编码不一致问题
  5. 数据结构源码笔记(C语言):二叉排序树的基本操作算法
  6. pytorch安装实录(win10+cuda8+pycharm+anaconda)
  7. matplotlib更改networkx生成的图形的背景图。
  8. python数据采集框架_20190715《Python网络数据采集》第 1 章
  9. 线程的状态 Thread.State||NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED
  10. JavaScript 技术篇-js代码获取当前操作系统信息、浏览器版本信息实例演示,windows NT版本对照表