B. Hongcow Solves A Puzzle
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #385 //再遇状压
敲完三题挂机一小时..... 也没懂DE什么意思 rank600上了一波分... A. Hongcow Learns the Cyclic Shift 给一个字符串,每次可以把最后一个字符拿到开头 ...
- 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 ...
- 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 ...
- BNU7538——Clickomania——————【区间dp】
Clickomania Time Limit: 10000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Java clas ...
- Gaby Ivanushka(快排)
Gaby Ivanushka Once upon a time there lived a tsar that has a daughter — Beautiful Vasilisa. There w ...
- Clickomania(区间DP)
描述 Clickomania is a puzzle in which one starts with a rectangular grid of cells of different colours ...
- 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) ...
随机推荐
- iOS开发--URL中汉字出现乱码
NSURL *nurl=[[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF ...
- JSX 语法
jsx 不能直接运行,是被 babel-loader 中的 react 这个 preset 翻译的 需要注意: 1.必须被一个单独的大标签包裹,比如:div 或者 section 2.标签必须封闭 3 ...
- POJ训练计划2299_Ultra-QuickSort(线段树/单点更新)
解题报告 题意: 求逆序数. 思路: 线段树离散化处理. #include <algorithm> #include <iostream> #include <cstri ...
- A7139 无线通信驱动(STM32) 添加FIFO扩展模式,能够发送超大数据包
A7139 拥有电磁波唤醒以及10mW的发射功率,很easy实现长距离通信,眼下測试有障碍物能够轻松达到300m以上. 通过几天的调试,眼下能够发送随意大小的数据包,大小为1-16KB.所有使用中断收 ...
- Git撤销&回滚操作
开发过程中.你肯定会遇到这种场景: 场景一: 糟了.我刚把不想要的代码.commit到本地仓库中了.可是还没有做push操作! 场景二: 彻底完了.刚线上更新的代码出现故障了.须要还原这次提交的代码! ...
- 链接脚本在编程中的高级运用之二——执行时库和C++特性支持
我们在链接脚本在编程中的高级运用之中的一个可变长数组中已经讲述了编译链接的原理,并且以uboot命令为例具体介绍链接脚本怎样实现可变长数组. 本章在前者的基础上继续讲述链接脚本在执行时库中的高级应用技 ...
- Navicat for MySQL出现1030-Got error 28 from storage engine错误
Navicat for MySQL出现1030-Got error 28 from storage engine错误 刚刚还能用这会儿就用不了了,估计是磁盘空间不足引起的! 在根目录/下执行命令:d ...
- 2012年公司组织旅游西安线个人记录(repost)
2012年公司组织旅游西安线个人记录 文件夹 [隐藏] 1 序言 2 第1天 3 第2天 4 第3天 5 第4天 6 第5天 [title=2012%E5%B9%B4%E5%85%AC%E5%8F% ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>
MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...
- iOS开发——高级篇——多线程dispatch_apply
我们知道遍历数组是一个相对耗时的操作,而同时手机的核是越来越多,所以我们需要充分利用iOS多核的作用. 特别是在遍历操作中还有其他耗时操作.像我们平时直接遍历数组的操作 ,i< ,i++){ / ...