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 }
     
  • 相关阅读:
    java:编写jar包加密工具,防止反编译
    Linux:CentOS-7常用命令
    MyBatis:MyBatis-Plus条件构造器EntityWrapper
    SpringBoot:SpringBoot项目的配置文件放在Jar包外加载
    机械学习导
    如何選擇最佳的 Wi-Fi 無線網路頻道,獲得最佳的傳輸速度(转载)
    解决ubuntu下filezilla登录ftp看不到中文目录和文件的问题 (转载)
    输入前几个字母,用箭头就能找出开头字母相同的历史命史
    Linux系统下使用split命令分割大文件 (转载)
    删除文件时排除特定文件 (转载)
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5691177.html
Copyright © 2011-2022 走看看