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

    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
    题意理解:一个人站在一个位置可以把同一行同一列的*消除,问有没有一个位置能够把所有的*消除,输出此坐标,没有则输出NO
    思路:记录*的总数sum并记录每一行a[i],每一列b[j],的*的数量,然后遍历,如果当前坐标s[i][j]=='*',此时叠了一个,将a[i]+b[j]-1于sum做比较,相等则停止,输出当前坐标,
    如果当前坐标s[i][j]!='*',则直接将a[i]+b[j]于sum做比较,相等则停止,输出当前坐标,否则输出NO。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m,sum=0;
     4 char s[1010][1010];
     5 int a[1010]= {0},b[1010]= {0};
     6 int main() {
     7     scanf("%d%d",&n,&m);
     8     for(int i=1; i<=n; i++) {
     9         for(int j=1; j<=m; j++) {
    10             cin>>s[i][j];
    11             if(s[i][j]=='*') {
    12                 a[i]++;
    13                 b[j]++;
    14                 sum++;
    15             }
    16         }
    17     }
    18     for(int i=1; i<=n; i++) {
    19         for(int j=1; j<=m; j++) {
    20             int ss=a[i]+b[j];
    21             if(s[i][j]=='*')
    22                 ss--;
    23             if(ss==sum) {
    24                 printf("YES
    %d %d
    ",i,j);
    25                 return 0;
    26             }
    27 
    28         }
    29     }
    30     printf("NO
    ");
    31     return 0;
    32 }
     
  • 相关阅读:
    对 HTTP 304 的理解(转-并增加自己的测试)
    山寨云主机充斥市场 教您辨别真假云主机
    JavaScript判断字符串是否含有中文(实用)
    ThinkPHP CURD返回结果参考
    Linux下修改网卡的mac地址
    Asterisk重要App
    Validation(3)--全局参数异常校验捕获及返回XML解决
    Validation(2)
    Validation(1)
    Mybatis分页中遇到的坑2
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5691177.html
Copyright © 2011-2022 走看看