CF 363B One Bomb(枚举)
题目链接: 传送门
One Bomb
time limit per test:1 second memory limit per test:256 megabytes
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.
Sample Input
3 4
.*..
....
.*..
3 3
..*
.*.
*..
6 5
..*..
..*..
*****
..*..
..*..
..*..
Sample Output
YES
1 2
NO
YES
3 3
思路:
题目大意:在一个矩阵中,是否能用一个炸弹炸掉所有的墙(炸弹以自己为中心呈十字引爆)
To solve this problem we need to calculate two arrays V[] and G[], where V[j] must be equal to the number of walls in the column number j and G[i] must be equal to the number of walls in the row number i. Also let's store the total number of walls in the variable cur.
Now we need to look over the cells. Let the current cell be (x, y). Let's count the value cur — how many walls will destroy the bomb planted in the cell (x, y): cnt = V[y] + G[x]. If the cell (x, y) has a wall we count it twice, so we need to subtract 1 from the cnt. If cur = cnt we found the answer and need to plant the bomb in the cell (x, y).
If there is no such cell we need to print "NO".
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N,M;
int r[1005],c[1005];
char maze[1005][1005];
int cnt = 0;
bool OK()
{
int sum = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
sum = r[i]+c[j];
if (maze[i][j] == '*')
{
sum--;
}
if (sum == cnt)
{
printf("YES\n%d %d\n",i+1,j+1);
return true;
}
}
}
return false;
}
int main()
{
while (~scanf("%d%d",&N,&M))
{
cnt = 0;
memset(maze,0,sizeof(maze));
memset(r,0,sizeof(r));
memset(c,0,sizeof(c));
for (int i = 0; i < N; i++)
{
getchar();
for (int j = 0; j < M; j++)
{
scanf("%c",&maze[i][j]);
if (maze[i][j] == '*')
{
r[i]++;
c[j]++;
cnt++;
}
}
}
if (!OK())
printf("NO\n");
}
return 0;
}
CF 363B One Bomb(枚举)的更多相关文章
- CF#FF(255)-div1-C【水题,枚举】
[吐槽]:本来没打算写这题的题解的,但惨不忍睹得WA了13次,想想还是记录一下吧.自己的“分类讨论能力”本来就很差. 刚开始第一眼扫过去以为是LIS,然后忽略了复杂度,果断TLE了,说起来也好惭愧,也 ...
- CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
The heat during the last few days has been really intense. Scientists from all over the Berland stud ...
- CF - 1108 E 枚举上界+线段树维护
题目传送门 枚举每个点作为最大值的那个点.然后既然是作为最大值出现的话,那么这个点就是不需要被减去的,因为如果最小值也在这个区间内的话,2者都减去1,对答案没有影响,如果是最小值不出现在这个区间内的话 ...
- CF #635D Xenia and Colorful Gems 枚举+二分
Xenia and Colorful Gems 题意 给出三个数组,在每个数组中选择一个数字x,y,z,,使得\((x-y)^2+(y-z)^2+(x-z)^2\)最小. 思路 我们假设x<=y ...
- 【二进制枚举】【CF Div2 C】
2022.3.4 https://codeforces.com/contest/1646/problem/C 题意: 给一个数, 问可以最少有几个以下的数构成: 1.x! 2.2^x(x在每次都是任 ...
- CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- codeforces 460D Little Victor and Set(构造、枚举)
最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...
随机推荐
- 大数据下多流形聚类分析之谱聚类SC
大数据,人人都说大数据:类似于人人都知道黄晓明跟AB结婚一样,那么什么是大数据?对不起,作为一个本科还没毕业的小白实在是无法回答这个问题.我只知道目前研究的是高维,分布在n远远大于2的欧式空间的数据如 ...
- 工作随笔——pre-commit钩子限制日志长度和提交的文件类型
2014-09-18:解决Subversion edge 的hook中文乱码问题 近期检查SVN时发现备份好的文件体积异常庞大.才跑2个月备份出来的大小就有4G多.仔细查询发现很多很多IDE自动生成的 ...
- Theano2.1.3-基础知识之更多的例子
来自:http://deeplearning.net/software/theano/tutorial/examples.html More Examples 现在,是时候开始系统的熟悉theano的 ...
- 20160303 - 升级 Windows 10 版本 1511 后,文件夹默认打开方式为 cmd 的修复
问题描述:升级 Windows 10 版本 1511 (OS 内部版本 10586.122)后,文件夹的默认打开方式变成了cmd.双击任何一个文件夹,显示相关的提示错误信息如下: [Window Ti ...
- dnsunlocker解决
环境:windows 10 中文企业版,firefox47, chrome51 安装了某个国外程序后,浏览器各种不正常,打开网页慢,或是无法打开,更严重的是会弹广告,各种广告. 然后在控制面板中卸载了 ...
- Tomcat本地服务器搭建
首先,下载jdk-8u111-windows-x64.exe,然后配置环境,以安装目录D:\jdk1.8.0_111为例: 新建一个变量: 然后打开path新建两个变量: 最后去控制台敲javac或者 ...
- ElasticSearch入门系列(三)文档,索引,搜索和聚合
一.文档 在实际使用中的对象往往拥有复杂的数据结构 Elasticsearch是面向文档的,这意味着他可以存储整个对象或文档,然而他不仅仅是存储,还会索引每个文档的内容使之可以被搜索,在Elastic ...
- SpringMVC学习--json
简介 json数据格式在接口调用中.html页面中较常用,json格式比较简单,解析还比较方便.比如:webservice接口,传输json数据. springmvc与json交互 @RequestB ...
- mysql常用方法学习
环境 create table phople ( id int(11) not null primary key auto_increment, name char(20) not null, sex ...
- HTML5基础知识(4)--white-space属性
1.white-space 属性设置如何处理元素内的空白. 这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的. 默认值: no ...