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. Java EE学习笔记(五)

    Spring事务管理 1.Spring事务管理概述 1).在实际开发中,操作数据库时都会涉及到事务管理问题,为此Spring提供了专门用于事务处理的API.(事务特性:ACID,原子性,一致性,隔离性 ...

  2. go time笔记

    package main import ( "time" "fmt" ) func main() { t := time.Now().UnixNano() fm ...

  3. e​c​s​h​o​p​调​用​商​品​简​单​描​述

    在下面文件 recommend_new.lbi recommend_best.lbi recommend_hot.lbi cat_goods.lbi 里调用商品简单描述用:{$goods.brief} ...

  4. 对象(Object)和类(Class)的关系?

    对象属于某一类,即对象是某一个类的实例.例如: Public Class Flight Private _name As String Public Property Name As String G ...

  5. javaScript中的严格模式 (译)

    “use strict”状态指示浏览器使用严格模式,是javaScript中一个相对少且安全的特征集. 特征列表(非完全列举) 不允许定义全局变量.(捕获没有用var声明的变量和变量名的拼写错误) 在 ...

  6. win10下vs2013为程序集新建强名称文件时“未能完成操作。拒绝访问”的解决方案

    昨日,在使用vs2013开发开发一个小工具,打算给这个小工具的源代码进行保护. 在输入完成建立强名称密钥文件时,爆出了如下错误: 一开始以为是项目所在路径的权限问题,于是给项目所在路径文件夹添加了“U ...

  7. selenium-Python之进行文件的上传和下载文件

    在利用Selenium进行批量上传文件时,遇到如下的Windows窗口进行上传.下载操作时,可以通过pywinauto进行操作.上传窗口如下 使用pywinauto,需知Windows窗口控件的cla ...

  8. SQL 基本编程

    定义变量 赋值 取值 分支语句 循环语句 定义变量 declare @变量   数据类型          //@必须带着  不然程序不知道变量是什么  不带@   电脑会报错 例如 declare ...

  9. Slacklining 2017/2/6

    原文 Get ready for a different kind of challenge What happens when mountain climbers take a day off?Ap ...

  10. 基于Vmware player的Windows 10 IoT core + RaspberryPi2安装部署

    本文记录了基于Vmware Player安装Windows10和VS2015开发平台的过程,以及如何在RaspberryPi2.0上启动Windows10 IoT core系统,并通过一个简单的hel ...