-
Notifications
You must be signed in to change notification settings - Fork 6
/
reservoi.cpp
98 lines (91 loc) · 2.87 KB
/
reservoi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<bits/stdc++.h>
#define MAX 100000
#define DEBUG(x) do { std::cout << #x << ": " << x << std::endl; } while (0)
using namespace std;
int main(){
int t,n,m,flag,i,j,temp,x;
char tank[1000][1000]={0};
cin>>t;
while(t--){
cin>>n>>m;
for(i=0;i<n;++i){
cin>>tank[i];
}
flag=1;
for(i=0;i<n;++i)
{
for(j=0;j<m;++j)
{
if(tank[i][j]=='B')
{
if(i+1<n) //check below
{
if(tank[i+1][j]=='W' || tank[i+1][j]=='A'){
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<" ";
break;
}
}
}
else if(tank[i][j]=='W')
{
if(j==0 || j==m-1) //left and right boundary
{
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<"1 ";
break;
}
else if(j-1>=0 && tank[i][j-1]=='A')//check left
{
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<"2 ";
break;
}
else if(j+1<m && tank[i][j+1]=='A')//check right
{
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<"3 ";
break;
}
else if(i+1<n) //check below
{
if(tank[i+1][j]=='A'){
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<"4 ";
break;
}
}
else if(i-1>=0) //check above
{
if(tank[i-1][j]=='B'){
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<"5 ";
break;
}
}
}
else if(tank[i][j]=='A')
{
if(i-1>=0) //check above
{
if(tank[i-1][j]=='B' || tank[i-1][j]=='W'){
flag=0;
//cout<<tank[i][j]<<" "<<i<<" "<<j<<" ";
break;
}
}
}
}
if(flag==0){
break;
}
}
if(flag==0){
cout<<"no\n";
}
else{
cout<<"yes\n";
}
}
return 0;
}