Plus from Picture

Plus from Picture

You have a given picture with size w×hw×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.
Input
The first line contains two integers hh and ww (1≤h1≤h, w≤500w≤500) — the height and width of the picture.
The ii-th of the next hh lines contains string sisi of length ww consisting “.” and “" where “.” denotes the empty space and "” denotes the non-empty space.
Output
If the given picture satisfies all conditions, print “YES”. Otherwise, print “NO”.
You can output each letter in any case (upper or lower).
Examples

Examples
Input
Copy
5 6
......
..*...
.****.
..*...
..*...
Output
Copy
YES
Input
Copy
3 5
..*..
****.
.*...
Output
Copy
NO
Input
Copy
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
Copy
NO
Input
Copy
5 6
..**..
..**..
******
..**..
..**..
Output
Copy
NO
Input
Copy
3 7
.*...*.
***.***
.*...*.
Output
Copy
NO
Input
Copy
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
Copy
NO
Note

In the first example, the given picture contains one "+".

In the second example, two vertical branches are located in a different column.

In the third example, there is a dot outside of the shape.

In the fourth example, the width of the two vertical branches is 22.

In the fifth example, there are two shapes.

In the sixth example, there is an empty space inside of the shape.

一开始以为是一道dfs题然后找几个区域块的那种题后来仔细读题发现是一道可以暴力的题 题意一个二维字符数组 要求这个二维数组里只存在一个构成”十“形状的图像.表示空白*来表示填充的字符。 思路 既然要只存在一个十那么我们只需要找到一个十并把它清除掉 如果说还是存在*那么就是不符合题意因为这个图型里只允许存在一个*组成的十并且没有其它多余的*所以我们只需要找到十字的中心然后把这个十删除 然后再便利一次如果还存在*那么就不和题否则就合题
#include <iostream>
#include <cmath>
#include<set>
#include <algorithm>
#include<string>
#include<string.h>
using namespace std;
int a[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char v[1000][1000];
void clearr(int x,int y)
{
    v[x][y]='.';
    for(int i=0;i<4;i++)
    {
        int x1=x,y1=y;
        while(v[x1+a[i][0]][y1+a[i][1]]=='*'){
            v[x1+a[i][0]][y1+a[i][1]]='.';
            x1+=a[i][0],y1+=a[i][1];
        }
    }

}
int main()
{
    string s;
    char ss[10000];
    int n,m,b[1000],flag1=0;
    while(cin>>m>>n)
    {
        memset(v,0,sizeof(v));
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                cin>>v[i][j];
            }
        }
        flag1=1;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(v[i][j]=='*'&&v[i+1][j]=='*'&&v[i-1][j]=='*'&&v[i][j+1]=='*'&&v[i][j-1]=='*'&&i+1<=m&&i-1>=1&&j+1<=n&&j-1>=1)
                {
                    flag1=0;
                    clearr(i,j);
                    goto l;
                }
            }
        }
        l:int flag=0;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(v[i][j]=='*')
                {
                    flag=1;
                }
            }
        }
        if(flag1==1||flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值