博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #566 (Div. 2) B. Plus from Picture
阅读量:6912 次
发布时间:2019-06-27

本文共 1968 字,大约阅读时间需要 6 分钟。

链接:

题意:

You have a given picture with size w×h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:

A "+" shape has one center nonempty cell.

There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
All other cells are empty.
Find out if the given picture has single "+" shape.

思路:

遍历每一个点,当某个点的上下左右都为时。向四个方向扩展,记录的个数。之后结束遍历。

当某个点可以形成+且的个数等于所有*的个数的时候,YES。

代码:

#include 
using namespace std;typedef long long LL;const int MAXN = 1e3 + 10;const int MOD = 1e9 + 7;int n, m, k, t;char pi[MAXN][MAXN];int main(){ scanf("%d %d", &n, &m); getchar(); int sum = 0; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { scanf("%c", &pi[i][j]); if (pi[i][j] == '*') sum++; } getchar(); } bool flag = false; for (int i = 2;i <= n-1;i++) { for (int j = 2;j <= m-1;j++) { if (pi[i][j]=='*'&&pi[i-1][j]=='*'&&pi[i][j+1]=='*'&&pi[i+1][j]=='*'&&pi[i][j-1]=='*') { flag = true; sum--; int tx, ty; tx = i-1, ty = j; while (tx >= 1 && pi[tx][ty] == '*') tx--, sum--; tx = i, ty = j+1; while (ty <= m && pi[tx][ty] == '*') ty++, sum--; tx = i+1, ty = j; while (tx <= n && pi[tx][ty] == '*') tx++, sum--; tx = i, ty = j-1; while (ty >= 1 && pi[tx][ty] == '*') ty--, sum--; } if (flag) break; } cerr << endl; if (flag) break; } if (flag && sum == 0) printf("YES\n"); else printf("NO\n"); return 0;}

转载于:https://www.cnblogs.com/YDDDD/p/11009840.html

你可能感兴趣的文章
[更新]Luke.Net for Pangu 盘古分词版更新
查看>>
jsp 生成静态页面
查看>>
ipad 使用UIImageView显示网络上的图片
查看>>
转: std::string用法详解
查看>>
【入门经典】Master和Content页面之一
查看>>
pku 2513 Colored Sticks trie树+并查集+欧拉路的判断
查看>>
淘宝技术发展(Oracle/支付宝/旺旺)(Java时代:脱胎换骨)
查看>>
纠错【2012年5月9日 JQuery-跑马灯(文字无缝向上翻动)(自已封装的第三个插件)】...
查看>>
Java编程的逻辑 (3) - 基本运算
查看>>
postgresql 死锁处理
查看>>
sum-of-two-integers
查看>>
编译器 cc、gcc、g++、CC 的区别
查看>>
SQL Server2014 SP2新增的数据库克隆功能
查看>>
USACO 状压DP练习[3]
查看>>
Gdb远程调试Linux内核遇到的Bug
查看>>
bzoj 3509: [CodeChef] COUNTARI] [分块 生成函数]
查看>>
调整Redmine的用户显示格式
查看>>
Objc执行时读取和写入plist文件遇到的问题
查看>>
Hadoop生态圈-Kafka的完全分布式部署
查看>>
Lucene全文检索
查看>>