Codeforces Round #228 (Div. 2)B. Fox and Cross

来源:互联网 发布:wamp无法运行php 编辑:程序博客网 时间:2024/06/05 08:32
B. Fox and Cross
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.

A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.

Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.

Please, tell Ciel if she can draw the crosses in the described way.

Input

The first line contains an integer n (3 ≤ n ≤ 100) — the size of the board.

Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.

Output

Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".

Sample test(s)
input
5.#...####..####...#......
output
YES
input
4################
output
NO
input
6.#....####...####..#.##.######.#..#.
output
YES
input
6.#..#.######.####..####.######.#..#.
output
NO
input
3.........
output
YES
Note

In example 1, you can draw two crosses. The picture below shows what they look like.

In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.

比赛时还看错题意了,以为还可以自己添加形成十字架;

#include <cstdio>#include <cstring>char stu[110][110];int n;int main(){    int i,j;    while(~scanf("%d",&n))    {        memset(stu,0,sizeof(stu));        getchar();        for(i=1;i<=n;++i)        {                for(j=1;j<=n;++j)            {                scanf("%c",&stu[i][j]);            }            getchar();        }        if(stu[1][1]=='#'||stu[1][n]=='#'||stu[n][1]=='#'||stu[n][n]=='#')        {            printf("NO\n");continue;        }        for(i=1;i<=n;++i)        {            for(j=1;j<=n;++j)            {                if(stu[i][j]=='#')                {                if(i==1)                {                    if(stu[i+1][j]=='#'&&stu[i+2][j]=='#'&&stu[i+1][j-1]=='#'&&stu[i+1][j+1]=='#')                    {                        stu[i][j]='k';                        stu[i+1][j]='k';                        stu[i+2][j]='k';                        stu[i+1][j-1]='k';                        stu[i+1][j+1]='k';                    }                }                else if(i==n)                {                    if(stu[i-1][j]=='#'&&stu[i-2][j]=='#'&&stu[i-1][j-1]=='#'&&stu[i-1][j+1]=='#')                    {                        stu[i][j]='k';                        stu[i-1][j]='k';                        stu[i-2][j]='k';                        stu[i-1][j-1]='k';                        stu[i-1][j+1]='k';                    }                }                else if(j==1)                {                    if(stu[i][j+1]=='#'&&stu[i][j+2]=='#'&&stu[i-1][j+1]=='#'&&stu[i+1][j+1]=='#')                    {                        stu[i][j]='k';                        stu[i][j+1]='k';                        stu[i][j+2]='k';                        stu[i-1][j+1]='k';                        stu[i+1][j+1]='k';                    }                }                else if(j==n)                {                    if(stu[i][j-1]=='#'&&stu[i][j-2]=='#'&&stu[i-1][j-1]=='#'&&stu[i+1][j-1]=='#')                    {                        stu[i][j]='k';                        stu[i][j-1]='k';                        stu[i][j-2]='k';                        stu[i-1][j-1]='k';                        stu[i+1][j-1]='k';                    }                }                else                {                    if(stu[i][j-1]=='#'&&stu[i][j+1]=='#'&&stu[i+1][j]=='#'&&stu[i-1][j]=='#')                    {                        stu[i][j]='k';                        stu[i][j-1]='k';                        stu[i][j+1]='k';                        stu[i+1][j]='k';                        stu[i-1][j]='k';                    }                }                }            }        }        for(i=1;i<=n;++i)        {            for(j=1;j<=n;++j)            {                if(stu[i][j]=='#')               {                   printf("NO\n");goto loop;               }            }        }        printf("YES\n");        loop:;    }    return 0;}


0 0
原创粉丝点击