B. One Bomb (#363 Div.2)
B. One Bombtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputIf 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.
Examplesinput3 4
.*..
....
.*..outputYES
1 2input3 3
..*
.*.
*..outputNOinput6 5
..*..
..*..
*****
..*..
..*..
..*..outputYES
3 3
题意:你有一个炸弹,可以放在任意位置并炸掉该位置所在的行和列上的墙“*”,求一颗炸弹是否能炸掉所有的墙。
我们可以将每行和每列的墙数分别存入数组x[]和y[]。每当a[i][j]的位置是"*"时,x[i]++,y[j]++;最后再将x[i]+y[j]与总墙数sum比较。
注意:当炸弹所在点为“*”时,需x[i]+y[j]-1;
附AC代码:
#include<iostream>
#include<cstring> using namespace std; int N,M,ans;
int a[][],x[],y[];
char s[]; void process(){
scanf("%d %d",&N,&M);
int cnt = ;
for(int i=; i<=N; i++){
scanf("%s",s);
for(int j=; j<=M; j++){
if(s[j-] == '*'){
x[i]++;
y[j]++;
cnt++;
a[i][j] = ;
}
}
}
for(int i=; i<=N; i++){
for(int j=; j<=M; j++){
int t;
t = x[i]+y[j];
if(a[i][j] == ) t--;//重复一个
if(t == cnt){
printf("YES\n%d %d\n",i,j);
return;
}
}
}
printf("NO\n");
} int main(){
process();
return ;
}
最新文章
- ABP框架 - 模块系统
- iOS中使用正则
- Hibernate 参数设置一览表
- ubuntu 双线双网卡双IP实现方式
- hdu 2177 取(2堆)石子游戏(威佐夫博奕)
- C++中,指针数组和数组指针
- SSD在SQLServer中的应用
- Unity多语言本地化改进版
- 使用PHP发送邮件
- ios import和@class的区别
- Searching a 2D Sorted Matrix Part I
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
- 在web网页中正确使用图片格式
- [daily] cscope
- Warning: count(): Parameter must be an array or an object that implements Countable in line 302解决方法
- 学会学习:高效学习方式(使用vscode-snippet有感)
- Python实现将爱词霸每日一句定时推送至微信
- 【mysql】 mysql忘记密码
- nmap 扫描信息收集
- c/c++保存日志程序模板