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. Memory Analysis环境安装

    安装MAT(MAT在eclipse的页面:http://www.eclipse.org/mat/downloads.php) 显示饼图的时候,需要安装BIRT Chart Engine插件,通过Ins ...

  2. 解决Install failed uid changed

    出现此问题的原因大多是apk冲突造成,解决的办法如下: 将apk相关文件和相关内容删除 (1) 将手机root,Window上装root大师等工具root成功率较高 (2) 删除可能相关的文件:/da ...

  3. MySQL 存储过程传參之in, out, inout 參数使用方法

    存储过程传參:存储过程的括号中.能够声明參数. 语法是 create procedure p([in/out/inout] 參数名  參数类型 ..) in :给參数传入值,定义的參数就得到了值 ou ...

  4. jsonp突破同源策略,实现跨域訪问请求

    版权声明:本文为博主原创文章,未经博主同意不得转载.如需转载请声明:[转自 http://blog.csdn.net/xiaoxian8023 ] https://blog.csdn.net/xiao ...

  5. POJ 1269 Intersecting Lines(线段相交,水题)

    id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...

  6. website项目的reference问题

    right click on website project--> property pages dll dependency Check the type column,if you have ...

  7. YTU 2975: 我的编号

    2975: 我的编号 时间限制: 1 Sec  内存限制: 128 MB 提交: 42  解决: 15 题目描述 建立一个学生链表,每个链表结点含有学生的基本信息,编号和姓名.现在n个学生站成一列,根 ...

  8. Kotlin 单例

    单例的实现方法,可以通过同伴对象,或者 lazy. 示例: class Hello private constructor() { companion object { val instance = ...

  9. AutoIT: 对Windows桌面的一些操作

    $handle= WinGetHandle("Program Manager") $ctrl= ControlGetHandle("ProgramManager" ...

  10. Combo Box (组合框)控件的使用方法

    Combo Box (组合框)控件很简单,可以节省空间.从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的.用户可以从一个预先定义的列表里选择一个选项,同时也可以直接在文本框里面输入文本 ...