zoukankan      html  css  js  c++  java
  • Codeforces Round #363 (Div. 2) B 暴力

    Description

    You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").

    You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.

    You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.

    Input

    The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.

    The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.

    Output

    If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).

    Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.

    Sample Input

    Input
    3 4
    .*..
    ....
    .*..
    Output
    YES
    1 2
    Input
    3 3
    ..*
    .*.
    *..
    Output
    NO
    Input
    6 5
    ..*..
    ..*..
    *****
    ..*..
    ..*..
    ..*..
    Output
    YES
    3 3

    题意:给你一个n*m的矩阵 ‘*’代表墙 现在只允许摆放一个炸弹 使得炸掉所有的墙
    若炸弹的坐标为(i,j) 则第i行和第j列所有的墙都会被炸掉;

    题解:预处理记录每一行每一列墙的个数
    枚举每一个位置 判断能否炸掉所有的墙

    hack数据
    2 2
    ..
    ..
    YES
    1 1
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<queue>
     5 #include<stack>
     6 #include<vector>
     7 #include<map>
     8 #include<algorithm>
     9 #define ll __int64
    10 #define mod 1e9+7
    11 #define PI acos(-1.0)
    12 using namespace std;
    13 int n,m;
    14 char mp[1005][1005];
    15 int h[1005];
    16 int l[1005];
    17 int main()
    18 {
    19     scanf("%d %d",&n,&m);
    20     memset(h,0,sizeof(h));
    21     memset(l,0,sizeof(l));
    22     getchar();
    23     int zha=0;
    24     for(int i=1;i<=n;i++)
    25     {
    26         for(int j=1;j<=m;j++)
    27         {
    28             scanf("%c",&mp[i][j]);
    29             if(mp[i][j]=='*')
    30             {
    31                 zha++;
    32                 h[i]++;
    33                 l[j]++;
    34             }
    35         }
    36         getchar();
    37     }
    38     for(int i=1;i<=n;i++)
    39     {
    40         for(int j=1;j<=m;j++)
    41        {
    42            if(mp[i][j]=='*')
    43            {
    44                if((h[i]+l[j]-1)==zha)
    45                {
    46                    cout<<"YES"<<endl;
    47                    cout<<i<<" "<<j<<endl;
    48                    return 0;
    49                }
    50            }
    51            else
    52            {
    53                if((h[i]+l[j])==zha)
    54                {
    55                    cout<<"YES"<<endl;
    56                    cout<<i<<" "<<j<<endl;
    57                    return 0;
    58                }
    59            }
    60 
    61        }
    62     }
    63     cout<<"NO"<<endl;
    64     return 0;
    65 }
  • 相关阅读:
    postgresql强制删除数据库
    oracle ORA-31655
    oracle 删除表空间与用户
    Nginx 配置文件说明
    docker学习笔记---基本命令
    SSH的 Write failed: Broken pipe 问题
    nginx 修改文件上传大小限制
    "echo 0 /proc/sys/kernel/hung_task_timeout_secs" disable this message
    Centos8 配置静态IP
    Prometheus Node_exporter 详解
  • 原文地址:https://www.cnblogs.com/hsd-/p/5687702.html
Copyright © 2011-2022 走看看