B. One Bomb (#363 Div.2)

B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

 

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.

 

Examples
input
3 4
.*..
....
.*..
output
YES
1 2
input
3 3
..*
.*.
*..
output
NO
input
6 5
..*..
..*..
*****
..*..
..*..
..*..
output
YES
3 3

 

题意:你有一个炸弹,可以放在任意位置并炸掉该位置所在的行和列上的墙“*”,求一颗炸弹是否能炸掉所有的墙。

我们可以将每行和每列的墙数分别存入数组x[]和y[]。每当a[i][j]的位置是"*"时,x[i]++,y[j]++;最后再将x[i]+y[j]与总墙数sum比较。

注意:当炸弹所在点为“*”时,需x[i]+y[j]-1;

 

附AC代码:

 1 #include<iostream>
 2 #include<cstring>
 3 
 4 using namespace std;
 5 
 6 int N,M,ans;
 7 int a[1002][1002],x[1002],y[1002];
 8 char s[200010];
 9 
10 void process(){
11     scanf("%d %d",&N,&M);
12     int cnt = 0;
13     for(int i=1; i<=N; i++){
14         scanf("%s",s);
15         for(int j=1; j<=M; j++){
16             if(s[j-1] == '*'){
17                 x[i]++;
18                 y[j]++;
19                 cnt++;
20                 a[i][j] = 1;
21             }
22         }
23     }
24     for(int i=1; i<=N; i++){
25         for(int j=1; j<=M; j++){
26             int t;
27             t = x[i]+y[j];
28             if(a[i][j] == 1) t--;//重复一个 
29             if(t == cnt){
30                 printf("YES\n%d %d\n",i,j);
31                 return;
32             }
33         }
34     }
35     printf("NO\n");
36 }
37 
38 int main(){
39     process(); 
40     return 0;
41 }

 

posted @ 2016-07-20 10:33  Kiven#5197  阅读(242)  评论(0编辑  收藏  举报