B. One Bomb (#363 Div.2)
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.
?
Examples input 3 4.*..
....
.*.. output YES
1 2 input 3 3
..*
.*.
*.. output NO input 6 5
..*..
..*..
*****
..*..
..*..
..*.. output YES
3 3
?
題意:你有一個(gè)炸彈,可以放在任意位置并炸掉該位置所在的行和列上的墻“*”,求一顆炸彈是否能炸掉所有的墻。
我們可以將每行和每列的墻數(shù)分別存入數(shù)組x[]和y[]。每當(dāng)a[i][j]的位置是"*"時(shí),x[i]++,y[j]++;最后再將x[i]+y[j]與總墻數(shù)sum比較。
注意:當(dāng)炸彈所在點(diǎn)為“*”時(shí),需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--;//重復(fù)一個(gè) 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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/Kiven5197/p/5687391.html
總結(jié)
以上是生活随笔為你收集整理的B. One Bomb (#363 Div.2)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java 和 Python 解析动态 k
- 下一篇: 【BZOJ2243】 [SDOI2011