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) ...
随机推荐
- Linux VPS/server上用Crontab来实现VPS自己主动化
VPS或者server上常常会须要VPS或者server上常常会须要定时备份数据.定时运行重新启动某个服务或定时运行某个程序等等,一般在Linux使用Crontab,Windows以下是用计划任务(W ...
- 实习生面试相关-b
面试要准备什么 有一位小伙伴面试阿里被拒后,面试官给出了这样的评价:“……计算机基础,以及编程基础能力上都有所欠缺……”.但这种笼统的回答并非是我们希望的答案,所谓的基础到底指的是什么? 作为一名 i ...
- mysql中“Table ‘’ is read only”的解决办法
之前是在linux下面直接Copy的data下面整个数据库文件夹,在phpMyAdmin里面重新赋予新用户相应权限后,drupal成功连接上数据库.但出现N多行错误提示,都是跟Cache相关的表是‘R ...
- MySQL运行计划不准确 -概述
为毛 MySQL优化器的运行计划 好多时候都不准确,不是最优的呢(cpu+io)??? 因素太多了:: 存在information_schema的信息是定期刷新上去的,好多时候不是最真的,甚至相差好大 ...
- Entity Framework底层操作封装V2版本号(3)
如今是附加的,组合查询须要的扩展类.大家知道lanmda表达式的组合条件比較麻烦,所以就加了一样一个类,方便进行组合查询: using System; using System.Collections ...
- caioj1275&&hdu4035: 概率期望值6:迷宫
期望的大难题,%%ZZZ大佬的解释,不得不说这是一道好题(然而膜题解都没完全看懂,然后就去烦ZZZ大佬) 简单补充几句吧,tmp的理解是个难点,除以tmp的原因是,当我们化简时,子节点也有一个B*f[ ...
- How to Execute Page_Load() in Page's Base Class?
https://stackoverflow.com/questions/2737092/how-to-execute-page-load-in-pages-base-class We faced th ...
- git pull ,git fetch ,git merge
git pull 是git fetch与git merge的组合. 有时候拆开使用,会更加的安全. 比如想比较,本地分支,与线上分支的差别,就可以先 git fetch 这样就可以,git diff ...
- I.MX6 MAC Address 导致的系统崩溃
/**************************************************************************** * I.MX6 MAC Address 导致 ...
- BZOJ_4199_[Noi2015]品酒大会_后缀自动机
BZOJ_4199_[Noi2015]品酒大会_后缀自动机 Description 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 酒家”和“首席 ...