http://codeforces.com/contest/745/problem/B

题目要求的是,给定一个图形,要求里面判断是否有矩形,且仅有一个

就是

XXX....

XXX...X

是不行的,因为有两个了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int n, m;
const int maxn = + ;
char str[maxn][maxn];
char sub[maxn][maxn];
int tonext[][] = {{, }, {, }, {, -}, {-, }};
bool vis[maxn][maxn];
void dfs(int x, int y) {
for (int i = ; i < ; ++i) {
int tx = x + tonext[i][];
int ty = y + tonext[i][];
if (tx >= && tx <= n && ty >= && ty <= m && !vis[tx][ty] && str[tx][ty] == 'X') {
vis[tx][ty] = true;
dfs(tx, ty);
}
}
}
bool check() {
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
if (str[i][j] == 'X' && !vis[i][j]) return false;
}
}
return true;
}
void work() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) {
scanf("%s", str[i] + );
}
int ans = ;
for (int i = ; i <= n; ++i) {
bool flag1 = false;
bool flag2 = false;
bool be = false;
for (int j = ; j <= m; ++j) {
if (str[i][j] == 'X') {
if (str[i - ][j] == 'X') {
if (be && !flag1) {
cout << "NO" << endl;
return;
}
flag1 = true;
}
if (str[i + ][j] == 'X') {
if (be && !flag2) {
cout << "NO" << endl;
return;
}
flag2 = true;
}
be = true;
}
if (str[i][j] == 'X' && flag1) {
if (str[i - ][j] != 'X') {
cout << "NO" << endl;
return;
}
}
if (str[i][j] == 'X' && flag2) {
if (str[i + ][j] != 'X') {
cout << "NO" << endl;
return;
}
}
}
}
// cout << "ff" << endl;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
if (str[i][j] == 'X') {
vis[i][j] = true;
dfs(i, j);
if (check()) {
cout << "YES" << endl;
} else cout << "NO" << endl;
return;
}
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

感觉我判断起来有点麻烦啊

B. Hongcow Solves A Puzzle的更多相关文章

  1. Codeforces Round #385 (Div. 2) B - Hongcow Solves A Puzzle 暴力

    B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow li ...

  2. Codeforces Round #385 (Div. 2) A,B,C 暴力,模拟,并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

  3. Codeforces Round #385 //再遇状压

    敲完三题挂机一小时.....  也没懂DE什么意思  rank600上了一波分... A. Hongcow Learns the Cyclic Shift 给一个字符串,每次可以把最后一个字符拿到开头 ...

  4. Codeforces Round #385 (Div. 2)A B C 模拟 水 并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

  5. 2018 - 2019 CTU Open Contest E. Locker Room 【后缀数组】

    任意门:http://codeforces.com/gym/101954/problem/E E. Locker Room time limit per test 2.0 s memory limit ...

  6. BNU7538——Clickomania——————【区间dp】

    Clickomania Time Limit: 10000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d      Java clas ...

  7. Gaby Ivanushka(快排)

    Gaby Ivanushka Once upon a time there lived a tsar that has a daughter — Beautiful Vasilisa. There w ...

  8. Clickomania(区间DP)

    描述 Clickomania is a puzzle in which one starts with a rectangular grid of cells of different colours ...

  9. UESTC_Eight Puzzle 2015 UESTC Training for Search Algorithm & String<Problem F>

    F - Eight Puzzle Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) ...

随机推荐

  1. 【 D3.js 进阶系列 — 1.0 】 CSV 表格文件的读取

    在入门系列的教程中.我们经常使用 d3.json() 函数来读取 json 格式的文件.json 格式非常强大.但对于普通用户可能不太适合,普通用户更喜欢的是用 Microsoft Excel 或 O ...

  2. vue 定义全局函数

    方法一:main.js 注入 (1)在main.js中写入函数 Vue.prototype.changeData = function (){ alert('执行成功'); } (2)在所有组件里可调 ...

  3. jsp导出身份证到excel时候格式不正确

    今天早上客户跟我说excel导出身份证的时候显示有的对有的不对,我一看原来身份证以X结尾的能够,其他都显示不对.身份正显示如图所看到的: 在网上搜了一下发现,原来excel看你数字列超过12位就会显示 ...

  4. 项目期复习总结1:背景图合并,hack,浏览器内核前缀,伪类after before

    文件夹: 1.背景图合并和CSS Spirit 2.PS基本快捷键 3.hack技术基本书写,为什么不用? 4.内核前缀 5.伪类afterbefore 1.背景图合并和CSS Spirit 背景图合 ...

  5. centos7 安装配置openstack-dashboard (官网openstack-juno版)

    感谢朋友支持本博客.欢迎共同探讨交流.因为能力和时间有限.错误之处在所难免.欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  6. 软件project

    Problem Description Merlin的软件project老师Max布置了开发一个软件的大作业.因为这是一个大型软件.所以单靠Merlin一个人不可能在预订的时间内做完,必须与其它人合作 ...

  7. [iOS]经常使用正則表達式

    经常使用正則表達式大全!(比如:匹配中文.匹配html) 匹配中文字符的正則表達式: [u4e00-u9fa5]    评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包含汉字 ...

  8. Nyquist–Shannon sampling theorem 采样定理

    Nyquist–Shannon sampling theorem - Wikipedia https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_s ...

  9. Spring Cloud Sleuth 中id的使用

    Spring Cloud Sleuth采用的是Google的开源项目Dapper的专业术语. Span:基本工作单元,发送一个远程调度任务 就会产生一个Span,Span是一个64位ID唯一标识的,T ...

  10. 单点登录原理及实现sso

    WEB的登录那些事 说道账户登录和注册,其实我们每天都在亲身感受着,像微博.知乎还有简书等等.我们总是需要定期的去重新登录一下,对于这种认证机制,我们都能说出来两个名词,Cookie.Session. ...