B. One Bomb

time limit per test1 second

memory limit per test256 megabytes

Problem 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.


就是一个大水题啊,当时看了半天居然没有反应。

可以先算出每一行,每一列的’*’的总和放在r[],c[]数组中,然后再枚举每一点为放炸弹的中心,判断当前r[i]+c[j](注意是否减一),是否是总和。


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
char maps[maxn][maxn];
int r[maxn],c[maxn];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m) != EOF)
{
for(int i=1;i<=n;i++)
scanf("%s",maps[i]+1);
int sum = 0;
for(int i=1;i<=n;i++)
{
int temp = 0;
for(int j=1;j<=m;j++)
{
if(maps[i][j] == '*')
temp++;
}
r[i] = temp;
sum += temp;
}
for(int j=1;j<=m;j++)
{
int temp = 0;
for(int i=1;i<=n;i++)
{
if(maps[i][j] == '*')
temp++;
}
c[j] = temp;
} bool flag = false;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int temp;
if(maps[i][j] == '*')//如果当前点是‘*’要减1
temp = r[i] + c[j] - 1;
else
temp = r[i] + c[j];
if(temp == sum)
{
printf("YES\n%d %d\n",i,j);
flag = true;
break;
}
}
if(flag)
break;
}
if(!flag)
printf("NO\n");
}
}

CodeForces:699B-One Bomb的更多相关文章

  1. CodeForces - 699B One Bomb

    题目地址:http://codeforces.com/contest/699/problem/B 题目大意: 一个矩阵,内容由‘.’和‘*’组成(‘.’ 空,‘*’ 代表墙),墙分布在不同位置,现找出 ...

  2. 【模拟】Codeforces 699B One Bomb

    题目链接: http://codeforces.com/problemset/problem/699/B 题目大意: N*M的图,*代表墙.代表空地.问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在 ...

  3. CodeForces:#448 div2 B. XK Segments

    传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...

  4. CodeForces:#448 div2 a Pizza Separation

    传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...

  5. Codeforces:68A-Irrational problem(暴力大法好)

    A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...

  6. CodeForces:148D-D.Bag of mice

    Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Program Description Th ...

  7. CodeForces:847D-Dog Show

    D. Dog Show time limit per test2 seconds memory limit per test256 megabytes Problem Description A ne ...

  8. CSAPP Lab2: Binary Bomb

    著名的CSAPP实验:二进制炸弹 就是通过gdb和反汇编猜测程序意图,共有6关和一个隐藏关卡 只有输入正确的字符串才能过关,否则会程序会bomb终止运行 隐藏关卡需要输入特定字符串方会开启 实验材料下 ...

  9. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. ;i<=q;i++) { scanf("%ld%ld% ...

随机推荐

  1. HDU6298(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6298 打表找规律: #include<bits/stdc++.h> usin ...

  2. 谈PHP中的钩子

    钩子,英文为hooks.在程序中应用相当广泛,但是究竟什么是钩子呢?本人介绍一下目前本人对钩子的理解和相关心得. 假如有这么一段程序流: function fun(){ funA(); funB(); ...

  3. shell脚本解析json文件

    安装jq扩展 下载:jq 根据自己系统下载对应的文件 cp jq-linux64 /usr/bin cd /usr/bin mv jq-linux64 jq chmod +x jq 使用方法 假设有个 ...

  4. Less的学习和使用

    官网 http://less.bootcss.com/usage/ 在线编译器 http://tool.oschina.net/less

  5. JDk安装及环境变量的配置

    一.JDK的安装 1.打开下载好的安装包(我在这里附上一个百度云连接,https://pan.baidu.com/s/1o3nx0kbmecAISeneGqykLQ    提取码:jnw6) 傻瓜式安 ...

  6. 微信小程序开发-微信登陆流程

    我们需要一个标识来记录用户的身份的唯一性,在微信中unionId就是我们所需要的记录唯一ID,那么如何拿到unionId就成了关键,我将项目分为小程序和 后台PHP代码两部分来讲. 从小程序代码说起 ...

  7. iOS Category实现原理

    iOS Category实现原理 实现原理 我们不主动引入 Category 的头文件,Category 中的方法都会被添加进主类中.我们可以通过 - performSelector: 等方式 对 C ...

  8. 我的CentOS6.5下及windows7下 安装composer与Yii2的过程

    用yii2以来,安装composer老是不成功,所以一直在windows下的php里,用直接解压的方法运行yii2. 后来越来越多的场合,需要用composer,终于下决心,要在Linux下搞掂它! ...

  9. 面向 AWS 专家的 Azure 云服务介绍

    本文是面向 AWS 专家的 Azure 云服务介绍,参考本文可以帮助大家“按图索骥”在 Azure 的平台上找到能满足自己需求的服务. 公有云市场经过多年发展,已经涌现出几家大规模的提供商,如 Azu ...

  10. MySQL存储引擎问题

    一.什么是存储引擎 数据库就是一种对数据进行管理和存储的软件,而它能够实现存储和管理数据的原因就是因为存储引擎的存在,存储引擎就是对存储数据.为存储的数据建立索引以及更新.查询数据等技术的实现方法:在 ...