题目链接: 传送门

One Bomb

time limit per test:1 second     memory limit per test:256 megabytes

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

3 4
.*..
....
.*..

3 3
..*
.*.
*..

6 5
..*..
..*..
*****
..*..
..*..
..*..

Sample Output

YES
1 2

NO

YES
3 3

思路:

题目大意:在一个矩阵中,是否能用一个炸弹炸掉所有的墙(炸弹以自己为中心呈十字引爆)
To solve this problem we need to calculate two arrays V[] and G[], where V[j] must be equal to the number of walls in the column number j and G[i] must be equal to the number of walls in the row number i. Also let's store the total number of walls in the variable cur.
Now we need to look over the cells. Let the current cell be (x, y). Let's count the value cur — how many walls will destroy the bomb planted in the cell (x, y): cnt = V[y] + G[x]. If the cell (x, y) has a wall we count it twice, so we need to subtract 1 from the cnt. If cur = cnt we found the answer and need to plant the bomb in the cell (x, y).
If there is no such cell we need to print "NO".

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N,M;
int r[1005],c[1005];
char maze[1005][1005];
int cnt = 0;
bool OK()
{
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            sum = r[i]+c[j];
            if (maze[i][j] == '*')
            {
                sum--;
            }
            if (sum == cnt)
            {
                printf("YES\n%d %d\n",i+1,j+1);
                return true;
            }
        }
    }
    return false;
}

int main()
{
    while (~scanf("%d%d",&N,&M))
    {
        cnt = 0;
        memset(maze,0,sizeof(maze));
        memset(r,0,sizeof(r));
        memset(c,0,sizeof(c));
        for (int i = 0; i < N; i++)
        {
            getchar();
            for (int j = 0; j < M; j++)
            {
                scanf("%c",&maze[i][j]);
                if (maze[i][j] == '*')
                {
                    r[i]++;
                    c[j]++;
                    cnt++;
                }
            }
        }
        if (!OK())
            printf("NO\n");
    }
    return 0;
}

CF 363B One Bomb(枚举)的更多相关文章

  1. CF#FF(255)-div1-C【水题,枚举】

    [吐槽]:本来没打算写这题的题解的,但惨不忍睹得WA了13次,想想还是记录一下吧.自己的“分类讨论能力”本来就很差. 刚开始第一眼扫过去以为是LIS,然后忽略了复杂度,果断TLE了,说起来也好惭愧,也 ...

  2. CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】

    The heat during the last few days has been really intense. Scientists from all over the Berland stud ...

  3. CF - 1108 E 枚举上界+线段树维护

    题目传送门 枚举每个点作为最大值的那个点.然后既然是作为最大值出现的话,那么这个点就是不需要被减去的,因为如果最小值也在这个区间内的话,2者都减去1,对答案没有影响,如果是最小值不出现在这个区间内的话 ...

  4. CF #635D Xenia and Colorful Gems 枚举+二分

    Xenia and Colorful Gems 题意 给出三个数组,在每个数组中选择一个数字x,y,z,,使得\((x-y)^2+(y-z)^2+(x-z)^2\)最小. 思路 我们假设x<=y ...

  5. 【二进制枚举】【CF Div2 C】

    2022.3.4  https://codeforces.com/contest/1646/problem/C 题意: 给一个数, 问可以最少有几个以下的数构成: 1.x! 2.2^x(x在每次都是任 ...

  6. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  7. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  8. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. codeforces 460D Little Victor and Set(构造、枚举)

    最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...

随机推荐

  1. <实训|第七天>横扫Linux磁盘分区、软件安装障碍附制作软件仓库

    期待已久的linux运维.oracle"培训班"终于开班了,我从已经开始长期四个半月的linux运维.oracle培训,每天白天我会好好学习,晚上回来我会努力更新教程,包括今天学到 ...

  2. 使用markdown编辑evernote(印象笔记)的常用方法汇总

    原文发表在我的博客主页,转载请注明出处 前言 正所谓工欲善其事,必先利其器,本文将要介绍的evernote和markdown都是程序员必备的工具 虽然国内现在有了很多evernote的替代品,做的比较 ...

  3. 使用 Eclipse 调试 Java 程序的技巧

    你应该看过一些如<关于调试的N件事>这类很流行的帖子 .假设我每天花费1小时在调试我的应用程序上的话,那累积起来的话也是很大量的时间.由于这个原因,用这些时间来重视并了解所有使我们调试更方 ...

  4. java文件cmd运行出现中文乱码

    今天刚开始学java,使用cmd命令执行java文件的时候,发现中文打出来是一串乱码. 于是就百度了一下,发现一个行之有效的方法. 首先使用命令:javac -encoding utf-8 Hello ...

  5. Android回调

    当A页面跳往B页面做一些操作后,再从B页面回到A页面时,A页面想要回去一些B页面操作的数据时,我们一般会使用回调. 1 public class MainActivity extends Activi ...

  6. 你需要知道的MySQL开源存储引擎TokuDB

    在四月份的Percona Live MySQL会议上, TokuDB庆祝自己成为开源存储引擎整一周年.我现在仍能记得一年前它刚创建时的官方声明与对它的期望.当时的情况非常有意思,因为它拥有帮助MySQ ...

  7. [转]扩展RBAC用户角色权限设计方案

    原文地址:http://www.iteye.com/topic/930648 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地 ...

  8. xgboost

    xgboost后面加了一个树的复杂度 对loss函数进行2阶泰勒展开,求得最小值, 参考链接:https://homes.cs.washington.edu/~tqchen/pdf/BoostedTr ...

  9. 编译php5.4的时候出现错误----configure: error: in `/usr/local/src/php540/php-5.4.0':

    错误如下:checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep - ...

  10. OkHttp:Java 平台上的新一代 HTTP 客户端

    OkHttp 简介 OkHttp 库的设计和实现的首要目标是高效.这也是选择 OkHttp 的重要理由之一.OkHttp 提供了对最新的 HTTP 协议版本 HTTP/2 和 SPDY 的支持,这使得 ...