链接:

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. 分享知识-快乐自己: Oracle数据库实例、用户、表、表空间之间关系

    数据库: Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件). 其实Oracle数据库的概念和其它数据库不一样,这里的数据库是一个操作系统只有一个库 ...

  2. Dat.gui 使用教程

    官方站点:http://workshop.chromeexperiments.com/examples/gui/ Dat.gui 使用教程:Dat.gui 是一个 GUI 组件,他可以为你的 demo ...

  3. Stamps

    链接 分析:dp[i][j]表示前i个数,组成j,最少需要多少个.dp[i][j]=min(dp[i-1][j],dp[i-1][j-k*v[i]]+k),则可以转化为完全背包问题,同样的方法进行降维 ...

  4. SQL 优化总结(三) SQL子句

    SQL子句 尽可能编写优化器可以优化的语句. 1. SELECT子句 (1) 在查询Select语句中用Where字句限制返回的行数,避免表扫描,如果返回不必要的数据,浪费了服务器的I/O资源,加重了 ...

  5. Java Security(JCE基本概念)

    Java Security网络环境中的安全隐患计算机安全OSI参考结构模型五类安全服务八类安全机制网络环境中的安全隐患1. 存储问题: 移动存储设备存储数据没有加密存在的安全隐患 2. 通信问题: 用 ...

  6. Redis 教程笔记

    简介: 开源BSD.key-value数据库.数据持久化(可将内存数据保存到磁盘中),提供多种数据结构. 支持数据备份(master-slave模式) 优势: 性能高.数据类型丰富.原子性.其他 Re ...

  7. ngd 查看ng2应用的组件树、路由树

    1.全局安装ngd npm install -g @compodoc/ngd-cli 2.在tsconfig的同级目录下使用ngd命令 ngd

  8. 【opencv学习笔记三】opencv3.4.0数据类型解释

    opencv提供了多种基本数据类型,我们这里分析集中常见的类型.opencv的数据类型定义可以在D:\Program Files\opencv340\opencv\build\include\open ...

  9. java&nbsp;Class类

    java Class类 Class类(在java.lang包中,Instances of the class Classrepresent classes and interfaces in a ru ...

  10. php分页问题

    这样子分: $total_record=50; //这里的50通过sql获取记录总数$list_num=5; //设置一页显示数量$temp=($page-1)*$list_num; $total_p ...