链接:

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的更多相关文章

  1. Codeforces Round #566 (Div. 2)

    Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...

  2. Codeforces Round #566 (Div. 2) C. Beautiful Lyrics

    链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...

  3. 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 ...

  4. 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} \] 思路 我们通过迭代发 ...

  5. Codeforces Round #566 (Div. 2)题解

    时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...

  6. Codeforces Round #566 (Div. 2)C(字符串,SET)

    #include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[ ...

  7. 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 ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Android 4.0 的 GridLayout

    设计素材代码: 1<?xml version="1.0" encoding="utf-8"?> 2<GridLayout//#http://w ...

  2. static语句块的执行时间

    package utfTest; public class Test01 { public static void main(String[] args) { //Person.show(); Sys ...

  3. ES搜索排序,文档相关度评分介绍——Vector Space Model

    Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...

  4. python基础-元组

    操作元组 获取元组中的值 tup1 = ('高数','计算机',2008,2016) tup2 = (1,2,3,4,5,6,7) #和list的一样,同样取下标1,2,3,4的值 print(&qu ...

  5. (转)HLS协议,html5视频直播一站式扫盲

    本文来自于腾讯bugly开发者社区,原文地址:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1277 视频直播这么火,再不学就 ou ...

  6. 牛客网暑期ACM多校训练营(第三场)G:Coloring Tree(函数的思想)

    之前两次遇到过函数的思想的题,所以这次很敏感就看出来了.可以参考之前的题: https://www.cnblogs.com/hua-dong/p/9291507.html Christmas is c ...

  7. 「NOIP2006」「LuoguP1064」 金明的预算方案(分组背包

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NNN元钱就行” ...

  8. poj 2420 A Star not a Tree?——模拟退火

    题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...

  9. BZOJ3772:精神污染

    浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...

  10. The type org.springframework.core.io.support.ResourcePatternResolver cannot be resolved. It is ind

    转自:https://blog.csdn.net/evilcry2012/article/details/49208909 缺包 spring-core-.RELEASE.jar