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;
}
  

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值