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)). ...
随机推荐
- 记 FineUI 官方论坛所遭受的一次真实网络攻击!做一个像 ice 有道德的黑客!
在开始正文之前,请帮忙为当前 排名前 10 唯一的 .Net 开源软件 FineUI 投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/code ...
- 3到6年的.NETer应该掌握哪些知识?
我们组的开发人力一直比较紧张,今年春节后,高层终于给了几个headcount,我们可以开始招人了.从三月初我们就开始找简历,渠道有拉钩,内推,我司自己的招聘网站和智联等.简历筛了很多,也打了很多电话, ...
- Bootstrap系列 -- 43. 固定导航条
很多情况之一,设计师希望导航条固定在浏览器顶部或底部,这种固定式导航条的应用在移动端开发中更为常见.Bootstrap框架提供了两种固定导航条的方式: .navbar-fixed-top:导航条固定 ...
- [转]史上最全的CSS hack方式一览
做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...
- C语言字符串与数字相互转换
在C/C++语言中没有专门的字符串变量,通常用字符数组来存放字符串.字符串是以“\0”作为结束符.C/C++提供了丰富的字符串处理函数,下面列出了几个最常用的函数. ● 字符串输出函数puts. ● ...
- 反距离权重插值inverse distance weighting,IDW
反距离权重 (IDW) 插值显式假设:彼此距离较近的事物要比彼此距离较远的事物更相似.当为任何未测量的位置预测值时,反距离权重法会采用预测位置周围的测量值.与距离预测位置较远的测量值相比,距离预测位置 ...
- Java 关键字static final使用总结
Static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,被static修饰的成员变量和成员方法独立于该类的任何对象.也就是说,它不依赖类特定的实例,被 ...
- [转]设计模式之六大原则——开闭原则(OCP)
原文地址:http://www.cnblogs.com/muzongyan/archive/2010/08/05/1793454.html 开闭原则(Open Closed Principle)是Ja ...
- swift项目实战--微博的未登录界面的实现,和监听未登录界面两个按钮的两种实现方法
1.未登录界面的实现 微博项目中,用户不登录的话,显示的是未登录的界面.项目中TabBarVC的子控制器都是tableViewVC,所以抽取了父类,让父类判断用户是否登录,决定显示什么样的界面.loa ...
- python练习之购物车脚本
# -*- coding:utf-8 -*- #简单的购物车小程序 author:李瑞鑫 shopping_car =[] product_list_tatol = "---product ...