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% ...
随机推荐
- django 之 rest framework
一 二 三 四 五 六 七 八
- BZOJ1257(数论知识)
感觉做法很神奇……想不到啊qwq 题目: Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值 其中k ...
- 前端之Html元素的分类
一.html元素可分为三大类:块元素.内联元素.可变元素 1.块元素: 常见块状元素:div,p,ul,ol,li,dl,dt,dd,form,hr,table,tr,td,h1-h6,filedse ...
- be seen doing和be seen to do的区别
1. be seen doing和be seen to do的区别 be seen doing表被看到正在做某事:be seen to do 表被看到做某事(不表进行) He was seen to ...
- Fragment(一)--Fragment用法常见问题
fragment notes fragment相关内容包括 基本定义与使用 回退栈内部实现 fragment通信(与activity 与fragment) DialogFragment VP + Fr ...
- 指定ip地址登陆服务器
[root@localhost ~]# cat /etc/hosts.allow ## hosts.allow This file contains access rules which are ...
- 小tip: 使用CSS将图片转换成黑白(灰色、置灰)[转]
小tip: 使用CSS将图片转换成黑白(灰色.置灰) 这篇文章发布于 2012年08月19日,星期日,20:41,归类于 css相关, SVG相关. 阅读 159943 次, 今日 146 次 ...
- 【iOS】UITableview cell 顶部空白的n种设置方法
我知道没人会主动设置这个东西,但是大家一定都遇到过这个问题,下面总结下可能是哪些情况: 1, self.automaticallyAdjustsScrollViewInsets = NO; 这个应该 ...
- labview密码忘记怎么办,如何破解labview密码,vi密码md5码破解重置
labview密码忘记了或者需要破解labview密码,可以找到vi文件的md5码,把里面的md5码拿到网站http://cmd5.la解密就可以了. 把vi文件的32位md5码放到网站cmd5.la ...
- 机器学习之-奇异值分解(SVD)原理详解及推导
转载 http://blog.csdn.net/zhongkejingwang/article/details/43053513 在网上看到有很多文章介绍SVD的,讲的也都不错,但是感觉还是有需要补充 ...