Codeforces Round #363 (Div. 2) B. One Bomb

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

题目大意:输入一个字符矩阵,字符包括'.' , '*',在一个位置引爆一个炸弹,
它能消除同行同列的‘*’。问是否存在这样的一个位置,放置一个炸弹引爆后能消除矩阵中所有的‘*’;

思路:首先记录矩阵中‘*’的个数,当遍历到一个点时,若这个点的同行同列的‘*’数等于总的个数,
这个点符合条件,则返回YES和坐标。
问题是怎么确定某个点的同行同列‘*’数? 我们知道这个点的‘*’数等于这一行的‘*’数加上这一列
的‘*’数(讨论这个点是否为‘*’),为了避免重复计算某个点的同行同列的‘*’数,可以用两个数组
分别记录第i行的‘*’数,第j列的‘*’数;
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 char map[1005][1005];
 6 int a[1005], b[1005];
 7 
 8 int main(){
 9     int n, m, i, j;
10     scanf("%d %d", &n, &m);
11     int sum = 0;
12     for(i = 1; i <= n; i++){
13         for(j = 1; j <= m; j++){
14             //scanf("%c", &map[i][j]);出错 
15             cin >> map[i][j];
16             if(map[i][j] == '*'){
17                 a[i]++;
18                 b[j]++;
19                 sum++;
20             }
21         }
22     }
23 
24     for(i = 1; i <= n; i++){
25         for(j = 1; j <= m; j++){
26             int s = a[i] + b[j];
27             if(((map[i][j] == '*') && (s == sum + 1)) || (map[i][j] == '.') && (s == sum)){
28                 printf("YES\n");
29                 printf("%d %d\n", i, j);
30                 return 0;
31             }
32         }
33     }
34 
35     printf("NO\n");
36     return 0;
37 }

 

 
posted @ 2016-07-30 11:59  琴影  阅读(310)  评论(0编辑  收藏  举报