zoukankan      html  css  js  c++  java
  • G

    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 (1h1≤h, w500w≤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

    Input
    5 6
    ......
    ..*...
    .****.
    ..*...
    ..*...
    
    Output
    YES
    
    Input
    3 5
    ..*..
    ****.
    .*...
    
    Output
    NO
    
    Input
    7 7
    .......
    ...*...
    ..****.
    ...*...
    ...*...
    .......
    .*.....
    
    Output
    NO
    
    Input
    5 6
    ..**..
    ..**..
    ******
    ..**..
    ..**..
    
    Output
    NO
    
    Input
    3 7
    .*...*.
    ***.***
    .*...*.
    
    Output
    NO
    
    Input
    5 10
    ..........
    ..*.......
    .*.******.
    ..*.......
    ..........
    
    Output
    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.

    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    char ch[500+5][500+5];
    int main()
    {
        TLE;
        int n,m,x,y,flag=1;
        while(cin>>n>>m)
        {
            for(int i=0; i<n; i++)
                for(int j=0; j<m; j++)
                {
                    cin>>ch[i][j];
                }
    
            int ans=0,xx=0;
            //debug(ch,n,m);
            int nx , ny;
            for(int i=0; i<n; i++)
            {
                for(int j=0; j<m; j++)
                {
                    if(ch[i][j]=='*' && ch[i][j-1]=='*' && ch[i][j+1]=='*' && ch[i-1][j]=='*' && ch[i+1][j]=='*'  && j-1>=0 && j+1<m && i-1>=0 && i+1<n)
                    {
                        ch[i][j] = '.';
                        for(int kkkk=0; kkkk<4; kkkk++)
                        {
                            nx = dir[kkkk][0] + i ;
                            ny = dir[kkkk][1] + j ;
                            while(ch[nx][ny]=='*')
                            {
                                ch[nx][ny] = '.';
                                nx += dir[kkkk][0];
                                ny += dir[kkkk][1];
                            }
                        }
                        xx=1;break;
                    }
                }
                if(xx) break;
            }
    
            int kk=0;
            for(int i=0; i<n; i++)
            {
                for(int j=0; j<m; j++)
                {
                    if(ch[i][j]=='*')
                    {
                        kk=1;
                        break;
                    }
                }
                if(kk) break;
            }
            if(xx==0 || kk )
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
        }
        ok;
    }
    所遇皆星河
  • 相关阅读:
    糍粑大叔的独游之旅-战斗!之弹道实现
    攻击判定流程研究: 瀑布算法、圆桌算法、混合算法解析
    GitHub排名TOP30的机器学习开源项目/贪心学院
    学习ES7+ES8
    k8s Ipvs 内部网络自动分配和内部网络一致ip地址,导致ip冲突
    Linux操作系统load average过高,kworker占用较多cpu
    chrome断点调试&&其他技巧
    Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
    记一次线上Java程序导致服务器CPU占用率过高的问题排除过程
    解决并发问题,数据库常用的两把锁(转)
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11618769.html
Copyright © 2011-2022 走看看