cf #363 b
1 second
256 megabytes
standard input
standard output
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.
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.
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.
3 4
.*..
....
.*..
YES
1 2
3 3
..*
.*.
*..
NO
6 5
..*..
..*..
*****
..*..
..*..
..*..
YES
3 3
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;
char ma[][];
int main(){
int n,m;
int x=-;
int y=-;
int hang[];
int lie[];
int cnt=;
scanf("%d%d",&m,&n);
for(int i=;i<m;i++) hang[i]=;
for(int j=;j<n;j++) lie[j]=;
for(int i=;i<m;i++){
scanf("%s",ma[i]);
}
for(int i=;i<m;i++){
for(int j=;j<n;j++){
if(ma[i][j]=='*'){
hang[i]++;
lie[j]++;
cnt++;
}
} }
for(int i=;i<m;i++){
for(int j=;j<n;j++){
int tmp=hang[i]+lie[j];
if(ma[i][j]=='*') tmp--;
if(tmp==cnt){
printf("YES\n%d %d",i+,j+);
return ;
}
}
}
printf("NO\n");
return ;
}
分别统计行和列中到墙的个数,如果某个 行和列中包含全部到墙,则为答案。
最新文章
- SIP学习笔记(转)
- java Proxy(代理机制)
- WingIDE中文乱码问题解决方法
- php的<;?php ?>;标签匹配
- windows完全支持C++11的轻量级编译器(官网MinGW和非官方的MinGW-builds)
- MAC中使用Vim和GCC编译C程序
- python多线程场景下print丢失
- jQuery each和js forEach用法比较
- PHP原生写的生成图片缩略图类
- c# 将object尝试转为指定对象
- linux下umask的使用讲解
- python发送网络请求
- 详解基于朴素贝叶斯的情感分析及 Python 实现
- luogu P1486 [NOI2004]郁闷的出纳员
- 003_vim使用tip
- c++ 多继承 公有,私有,保护
- 20172308 实验三《Java面向对象程序设计 》实验报告
- C++ Primer 5th 第19章 特殊工具与技术
- poj 3348:Cows(计算几何,求凸包面积)
- How to Get the Length of File in C
热门文章
- <;摘录>;字节对齐(强制对齐以及自然对齐)
- JS面向对象之作用域
- 【mybatis】mybatis中insert 主键自增和不自增的插入情况【mysql】
- Swift,数组
- [Git] git merge和rebase的区别
- 【日志处理、监控ELK、Kafka、Flume等相关资料】
- 二分求幂 - A^B(王道*)
- virtualbox虚拟机ubuntu操作系统,设置网络互通、访问,能访问虚拟机swoole的http服务
- 倍福TwinCAT(贝福Beckhoff)应用教程12.3 TwinCAT控制松下伺服 NC进阶
- 依据错误原理解决Hibernate执行出现No CurrentSessionContext configured!错误