• 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 }
  • 相关阅读:
    点击listview 的列头对其item进行自动排序
    将选择的图片显示在listview中,并显示filename,path和type
    【翻译】8 个可以节省时间的 C# 开发相关工具
    【原创】关于乘法运算的新思路
    【翻译】为什么我们要用抽象类?
    【翻译】如何使用 C# 的 BackgroundWorker
    【汉化】DevExpress插件中RichEdit控件的自定义汉化方法
    关于C#日期格式化问题
    C#获取(大陆)身份证基本信息的算法
    C#关于精确年龄的算法(精确到天)
  • 原文地址:https://www.cnblogs.com/hsd-/p/5687702.html
Copyright © 2020-2023  润新知