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. 在VC6.0中多线程编程演示样例(带同步信号量)

    直接上代码: #include <windows.h>//必要的头文件,使用Windows API函数 #include <stdio.h> int index = 0; in ...

  2. 【iOS系列】-iOS开发常用库文件总结

    这里是列举出得一部分,更多内容可参考https://github.com/darren90/Gather_iOS 码农周刊的总结 - 覆盖很广 调调的 - 很多开发相关内容都有体现 右滑返回的解决 - ...

  3. 正向代理tinyproxy使用总结

    使用tinyproxy的问题背景: 其实以前代理一直用的是apache,后来,那次有个任务要给ios的推送设置代理,任务很紧急,可是apache报错. 原因如下:APNS发送通知的端口2195,但是A ...

  4. 【bzoj2753】[SCOI2012]滑雪与时间胶囊

    #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...

  5. log4j_自定义样式参数意义

    #自定义样式 %c 输出所属的类目,通常就是所在类的全名 %C 输出Logger所在类的名称,通常就是所在类的全名 %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比 ...

  6. 如何获取板子上独有的ID号EXYNOS4412/Imx6ul【转】

    本文转载自:http://blog.csdn.net/u010871058/article/details/75637175 每个CPU,都有它固定的ID号,ID号就是这个CPU唯一的标识,它可能隐含 ...

  7. phpstorm更改sql文件匹配类型

    正常情况下,sql文件都有对应的文件类型.但是默认的sql文件只是关联普通的sql.很多语法都无法高亮,以及自动提醒.

  8. Android控件之HorizontalScrollView 去掉滚动条

    在默认情况下,HorizontalScrollView控件里面的内容在滚动的情况下,会出现滚动条,为了去掉滚动条, 只需要在<HorizontalScrollView/>里面加一句 and ...

  9. mac idea 内存

    vim /Applications/IntelliJ\ IDEA.app/Contents/bin/idea.vmoptions -Xms512m -Xmx2048m -XX:ReservedCode ...

  10. BZOJ_1195_[HNOI2006]最短母串_AC自动机+BFS+分层图

    BZOJ_1195_[HNOI2006]最短母串_AC自动机+BFS+分层图 Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2, ...