CodeForces:699B-One Bomb
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的更多相关文章
- CodeForces - 699B One Bomb
题目地址:http://codeforces.com/contest/699/problem/B 题目大意: 一个矩阵,内容由‘.’和‘*’组成(‘.’ 空,‘*’ 代表墙),墙分布在不同位置,现找出 ...
- 【模拟】Codeforces 699B One Bomb
题目链接: http://codeforces.com/problemset/problem/699/B 题目大意: N*M的图,*代表墙.代表空地.问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在 ...
- CodeForces:#448 div2 B. XK Segments
传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...
- CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- CodeForces:148D-D.Bag of mice
Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Program Description Th ...
- CodeForces:847D-Dog Show
D. Dog Show time limit per test2 seconds memory limit per test256 megabytes Problem Description A ne ...
- CSAPP Lab2: Binary Bomb
著名的CSAPP实验:二进制炸弹 就是通过gdb和反汇编猜测程序意图,共有6关和一个隐藏关卡 只有输入正确的字符串才能过关,否则会程序会bomb终止运行 隐藏关卡需要输入特定字符串方会开启 实验材料下 ...
- CodeForces 获得数据
针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. ;i<=q;i++) { scanf("%ld%ld% ...
随机推荐
- 基于PHP的正则表达式
用法 从某个字符抽取信息 用新文本替换匹配的文本 把字符串拆分成小块字符串组成的数组 基础 preg_match('/需要匹配的正则表达式/', '字符串'); 正则匹配模式 集合: [xxxx]-- ...
- java中代码执行顺序
静态代码块 -- >构造代码块 --> 构造方法静态代码块:只执行一次构造代码块:每次调用构造方法都执行 http://blog.csdn.net/wuhaiwei002/article/ ...
- Linux--NiaoGe-Service-07网络安全与主机基本防护
Linux系统内自带的防火墙有两层: 第一层:数据包过滤防火墙:IP Filtering和Net Filter 要进入Linux本机的数据包都会先通过Linux预先内置的防火墙(Net Filter) ...
- 从零开始利用vue-cli搭建简单音乐网站(八)
这是完成了预想中的最后两个功能:歌曲评论以及歌曲搜索. 1.评论效果: 用户点击评论按钮,评论框获取焦点. 输入之后点击提交,下方显示评论,用户名称以及日期.相应的用户也可以删除自己评论. 当然只能删 ...
- 倒计时器 CountDownTimer
使用介绍 开发中经常会遇到一些和倒计时有关的场景,比如发送验证码的按钮,会在点击发送后,显示倒计时间,倒计时结束后才能够刷新按钮,再次允许点击.为了不阻塞软件的运行,又要实时刷新界面,我们通常会用到 ...
- Objective-C Runtime Reference
This document describes the OS X Objective-C 2.0 runtime library support functions and data structur ...
- PHP识别二维码功能,php-zbarcode 安装
php-zbarcode是PHP识别二维码的扩展. 下面是安装方法,安装前要先安装ImageMagick.zbar. php-zbarcode 下载地址 安装ImageMagick: yum inst ...
- 安装Pywin32后无法正常引用pyd文件
1. 首先在官方下载pywin32 2.下载完成后,无法正常引用pyd文件 3.解决方案: python安装目录\Lib\site-packages\pywin32_system32\* 至 C:\W ...
- (五)maven之外置maven
eclipse外置maven eclipse内置的maven插件是固定版本,如果要用其他版本的maven,可以使用外置maven. ① 在菜单栏上点击“Windows”à“Preferences ...
- Java使用HtmlUnit抓取js渲染页面
需求: 需要采集js渲染的页面,有些网站的页面是js渲染的 实现: 基于HtmlUnit实现: public static void getAjaxPage() throws Exception{ W ...