• #228(div2)B. Fox and Cross


    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".

    Examples
    input
    5
    .#...
    ####.
    .####
    ...#.
    .....
    output
    YES
    input
    4
    ####
    ####
    ####
    ####
    output
    NO
    input
    6
    .#....
    ####..
    .####.
    .#.##.
    ######
    .#..#.
    output
    YES
    input
    6
    .#..#.
    ######
    .####.
    .####.
    ######
    .#..#.
    output
    NO
    input
    3
    ...
    ...
    ...
    output
    YES
    题意:问#是否能组成十字架,不可重复利用
    思路:模拟
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 char s[103][103];
     5 
     6 int main(){
     7     int n;
     8     cin>>n;
     9     int sum=0;
    10     for(int i=1;i<=n;i++){
    11         scanf("%s",s[i]+1);
    12         for(int j=1;j<=n;j++){
    13             if(s[i][j]=='#') sum++;
    14         }
    15     }
    16     if(sum%5!=0) cout<<"NO"<<endl;
    17     else {
    18         for(int i=1;i<=n;i++){
    19             for(int j=1;j<=n;j++){
    20                 if(s[i][j]=='#'){
    21                     if(s[i+1][j]=='#'&&s[i+2][j]=='#'&&s[i+1][j-1]=='#'&&s[i+1][j+1]=='#'){
    22                             s[i][j]='.';
    23                         s[i+1][j]='.';s[i+2][j]='.';s[i+1][j-1]='.';s[i+1][j+1]='.';
    24                     }
    25                     else {
    26                         cout<<"NO"<<endl;return 0;
    27                     }
    28                 }
    29             }
    30         }
    31         cout<<"YES"<<endl;
    32     }
    33 }
  • 相关阅读:
    1、听说过Redis吗?它是什么?
    55、数据库高并发是我们经常会遇到的,你有什么好的解决方案吗?
    54、数据库如何保证持久性?
    53、数据库如何保证原子性?
    52、数据库如何保证一致性?
    注解定义、基本语法和属性
    Macbook 装机必备--开发篇
    http
    python:beaufiful
    python-yield
  • 原文地址:https://www.cnblogs.com/hhxj/p/7099481.html
Copyright © 2020-2023  润新知