链接:

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. Spark- Linux下安装Spark

    Spark- Linux下安装Spark 前期部署 1.JDK安装,配置PATH 可以参考之前配置hadoop等配置 2.下载spark-1.6.1-bin-hadoop2.6.tgz,并上传到服务器 ...

  2. 2017SN多校D1T2 note:dp

    题意: 给你一个长度为n的字符串s,并且告诉你有m对字母不能相邻,问你最少在s中取出多少个字符能够使这个字符串合法. 题解: 表示状态: dp[i] = max num of letters 考虑到第 ...

  3. yii2 linux安装教程

    安装扩展 安装Yii最好的方式就是使用Composer安装,所以我们需要安装Composer,但是为了安装Composer,我们需要安装一下关于Composer和Yii2的许多扩展包,别担心下面的教程 ...

  4. Java的访问权限修饰符

    default或者friendly表示默认的访问权限修饰符.

  5. java面试题04

    1.就你所熟悉的银行业务面说一下,越详细越好 银行经验:手机银行  网上银行经验  怎么支付  转账  了解基本业务 2.了解工作流的控制,审批流程以及帐务处理么? java中怎么实现工作流.审批流程 ...

  6. 【Python】数组排序

    1.numpy库:argsort() argsort函数返回的是数组值从小到大的索引值(升序排列) 一维: In [1]: import numpy as np In [2]: x = np.arra ...

  7. 解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题[segfault at 18 ip 00007f78842b4bd0 sp 00007fff1995a818 error 4 in libpthread-2.17.so[7f78842ab000+16000]]

    解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题 [root@localhost sbin]# service zabbix-server start Redir ...

  8. S5pv210 HDMI 接口在 Linux 3.0.8 驱动框架解析

    作者:liukun321 咕唧咕唧 日期:2014.1.18 转载请标明作者.出处:http://blog.csdn.net/liukun321/article/details/18452663 本文 ...

  9. CF-816B

    B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...

  10. Python 如何连接并操作 Aws 上 PB 级云数据仓库 Redshift

    Python 如何连接并操作 Aws 上 PB 级云数据仓库 Redshift 一.简介 Amazon Redshift 是一个快速.可扩展的数据仓库,可以简单.经济高效地分析数据仓库和数据湖中的所有 ...