zoukankan      html  css  js  c++  java
  • B. One Bomb (#363 Div.2)

    B. One Bomb
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
     

    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.

    Examples
    input
    3 4
    .*..
    ....
    .*..
    output
    YES
    1 2
    input
    3 3
    ..*
    .*.
    *..
    output
    NO
    input
    6 5
    ..*..
    ..*..
    *****
    ..*..
    ..*..
    ..*..
    output
    YES
    3 3

    题意:你有一个炸弹,可以放在任意位置并炸掉该位置所在的行和列上的墙“*”,求一颗炸弹是否能炸掉所有的墙。

    我们可以将每行和每列的墙数分别存入数组x[]和y[]。每当a[i][j]的位置是"*"时,x[i]++,y[j]++;最后再将x[i]+y[j]与总墙数sum比较。

    注意:当炸弹所在点为“*”时,需x[i]+y[j]-1;

    附AC代码:

     1 #include<iostream>
     2 #include<cstring>
     3 
     4 using namespace std;
     5 
     6 int N,M,ans;
     7 int a[1002][1002],x[1002],y[1002];
     8 char s[200010];
     9 
    10 void process(){
    11     scanf("%d %d",&N,&M);
    12     int cnt = 0;
    13     for(int i=1; i<=N; i++){
    14         scanf("%s",s);
    15         for(int j=1; j<=M; j++){
    16             if(s[j-1] == '*'){
    17                 x[i]++;
    18                 y[j]++;
    19                 cnt++;
    20                 a[i][j] = 1;
    21             }
    22         }
    23     }
    24     for(int i=1; i<=N; i++){
    25         for(int j=1; j<=M; j++){
    26             int t;
    27             t = x[i]+y[j];
    28             if(a[i][j] == 1) t--;//重复一个 
    29             if(t == cnt){
    30                 printf("YES
    %d %d
    ",i,j);
    31                 return;
    32             }
    33         }
    34     }
    35     printf("NO
    ");
    36 }
    37 
    38 int main(){
    39     process(); 
    40     return 0;
    41 }
  • 相关阅读:
    大数据【一】集群配置及ssh免密认证
    安卓测试【三】adb简单命令及monkey使用
    安卓测试【二】eclipse离线安装ADT
    初始化对象的知识细节
    安卓测试【一】android sdk环境变量配置
    自动化测试用例排序(三个算法随机、贪心、额外贪心)
    java实现文件复制粘贴功能
    Javsssist用InsertAt()方法对语句插桩
    Javassist进行方法插桩
    JUnit手动设计测试方法以及与Randoop的自动生成测试的比较
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5687391.html
Copyright © 2011-2022 走看看