zoukankan      html  css  js  c++  java
  • #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 }
  • 相关阅读:
    Angular2基础03: 理解依赖注入
    关于HTPP状态码的实践:307的使用
    Angular2基础03:如何重置表单的验证状态?
    Angular2基础02:模板引用变量的使用
    Angular2基础01:理解及时编译(JIT)
    cordova05:配置应用图标与启动画面
    连续子数组的最大和
    从1到整数n中1出现的次数
    滑动窗口的最大值
    矩阵中的路径
  • 原文地址:https://www.cnblogs.com/hhxj/p/7099481.html
Copyright © 2011-2022 走看看