Codeforces Round #566 (Div. 2) B. Plus from Picture
链接:
https://codeforces.com/contest/1182/problem/B
题意:
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 <bits/stdc++.h>
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;
}
Codeforces Round #566 (Div. 2) B. Plus from Picture的更多相关文章
- Codeforces Round #566 (Div. 2)
Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...
- Codeforces Round #566 (Div. 2) C. Beautiful Lyrics
链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...
- Codeforces Round #566 (Div. 2) A. Filling Shapes
链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...
- Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)
传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...
- Codeforces Round #566 (Div. 2)题解
时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...
- Codeforces Round #566 (Div. 2)C(字符串,SET)
#include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 检测 iOS 系统网络权限被关闭
背景 一直都有用户反馈无法正常联网的问题,经过定位,发现很大一部分用户是因为网络权限被系统关闭,经过资料搜集和排除发现根本原因是: 第一次打开 app 不能访问网络,无任何提示 第一次打开 app 直 ...
- 分享知识-快乐自己:Excel快速导入Oracle 数据库
需求: oracle 数据库有一个student表,现有一个excel表:student.xlsx,需导入oracle数据库student表中. student表的拥有者是c##MLQ1 密码为:x ...
- linux cpu占用100%排查
某服务器上部署了若干tomcat实例,即若干垂直切分的Java站点服务,以及若干Java微服务,突然收到运维的CPU异常告警. 问:如何定位是哪个服务进程导致CPU过载,哪个线程导致CPU过载,哪段代 ...
- [Shell]grep命令
我是好文章的搬运工,原文来自ChinaUnix,博主scq2099yt,地址:http://blog.chinaunix.net/uid-22312037-id-4217835.html 一.基本用法 ...
- 示例的libevent的程序
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:auxten 链接:http://zhuanlan.zhihu.com/auxten/20315482 来源:知乎 /* ...
- Shell读取文件内容【转】
while read wOne wTwo wThreedo [ -z $wOne ] && continue #测试此行内容是否为空 xxx=$wOne ...
- ACM学习历程——UVA540 Team Queue(队列,map:Hash)
Description Team Queue Team Queue Queues and Priority Queues are data structures which are know ...
- 转:Serializable---序列化
Serializable 今天在看代码的时候,看到[Serializable],不明白是什么意思.查阅了网上的一些资料,才明白这是指给类添加序列化的特性,即添加后它就可以进行序列化,那什 ...
- CF-839B
B. Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard ...
- prototype for '类名::函数名'does not match any in class'类名'
函数声明和定义参数类型必须相同. 前置声明一定要放到名称空间内,代表该名称空间内的类.