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

题意:

让你找一个点,放一个炸弹,使所有的*都被炸掉,炸弹只影响行列,和炸弹的那个点

题解:

行列统计一下又多少个*,然后暴力枚举每一个点,看这行这列的*的个数是否达到了全部的*的个数

 1 #include<cstdio>
 2 #include<vector>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define pb push_back
 6 #define F(i,a,b) for(int i=a;i<=b;++i)
 7 using namespace std;
 8 typedef long long LL;
 9 int n,m,anx,any,cnt=0;
10 char g[1011][1011];
11 vector<int>Gu[1011],Gv[1011];
12 
13 int main(){
14     scanf("%d%d",&n,&m);
15     F(i,1,n){
16         getchar();
17         F(j,1,m){
18             g[i][j]=getchar();
19             if(g[i][j]=='*'){
20                 cnt++,anx=i,any=j;
21                 Gu[i].pb(j);
22                 Gv[j].pb(i);
23             }
24         }
25     }
26     if(cnt==1){
27         printf("YES
%d %d
",anx,any);
28         return 0;
29     }
30     F(i,1,n)F(j,1,m){
31         int ann=Gu[i].size()+Gv[j].size();
32         if(g[i][j]=='*')ann--;
33         if(ann==cnt){
34             printf("YES
%d %d
",i,j);
35         return 0;
36         }
37     }
38     puts("NO");
39     return 0;
40 }
View Code


 

原文地址:https://www.cnblogs.com/bin-gege/p/5696071.html