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. 关于gc日志中Desired Survivor的疑问和对象晋升老年代的小结

    问题背景 (下面的所有内容都是根据书上的Serial/Serial Old收集器下的情况) 在<深入理解JVM>一书中的——3.6.3长期存活的对象将进入老年代的介绍中, 一个例子的jvm ...

  2. shell脚本实现自动化备份

    1.备份规则: 在生产环境中有若干服务器需要定时将服务器中应用程序,以及数据库等进行备份.要求在本地服务器中保存近一周的备份,备份服务器中保存最近一月的备份文件.                    ...

  3. Vue 简单实用---代码可以直接用

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  4. Oracle如何创建表空间

    create user frame identified by tiger; grant create session to frame; grant create table to frame; g ...

  5. jQuery.Deferred(jQuery1.5-2.1)源码剖析

    jQuery.Deferred作为1.5的新特性出现在jQuery上,而jQuery.ajax函数也做了相应的调整.因此我们能如下的使用xhr请求调用,并实现事件处理函数晚绑定. var promis ...

  6. 前端开发神器 - Brackets

    做了几年的 .Net 项目开发,后来公司转 Java 语言开发,Java 做了还没一年,公司准备前后端分离开发,而我被分到前端! Brackets是一款基于web(html+css+js)开发的web ...

  7. Android Studio 遇到的java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessExce问题

    在将一个Eclipse的项目转移到AndroidStudio的过程中,碰到了的问题如下: Error:Execution failed for task ':learnChinese:mergeDeb ...

  8. Java文件操作系列[3]——使用jacob操作word文档

    Java对word文档的操作需要通过第三方组件实现,例如jacob.iText.POI和java2word等.jacob组件的功能最强大,可以操作word,Excel等格式的文件.该组件调用的的是操作 ...

  9. MySQL常用函数使用示例

    #从指定字符中,随机生成12位字符select substring('0123456789abcdefghijklmnopqrstuvwxyz',floor(0+RAND()*36),12); #显示 ...

  10. sql server 2008怎么设置不允许windows身份验证