#include <bits/stdc++.h>
#define scI(n) scanf("%d", &n)
#define scL(n) scanf("%lld", &n)
#define scS(n) scanf("%s", &n)
#define mn(n, m) (n > m)?m:n
#define mx(n, m) (n < m)?m:n
#define S 123
using namespace std;
typedef long long LL;
int dirX[] = {1, 0, -1, 0, -1, 1, 1, -1};
int dirY[] = {0, 1, 0, -1, -1, 1, -1, 1};
int n, m, cnt, vis[S][S];
string WetLand[S];
string line;
int dfs(int i, int j){
if(i < 0 || j < 0 || i >= n || j >= m || WetLand[i][j] == 'L' || vis[i][j])return 0;
vis[i][j] = 1;
cnt++;
for(int z = 0; z < 8; z++){
int px = i+dirX[z];
int py = j+dirY[z];
dfs(px, py)+1;
}
return cnt;
}
int main(){
int t;
bool sp = false;
scI(t);
getchar(); getchar();
while(t--){
n = 0, m = 0;
if(sp)puts("");
sp = true;
while(getline(cin, line) && line.size() > 0){
if(!line.size())break;
if(line[0] == 'W' || line[0] == 'L'){
if(!m)m = line.size();
WetLand[n] = line;
n++;
}
else{
istringstream cinn(line);
int x, y;
cinn >> x; cinn >> y;
cnt = 0;
memset(vis, 0, sizeof(vis));
cout << dfs(x-1, y-1) << endl;
}
}
}
return 0;
}
#define scI(n) scanf("%d", &n)
#define scL(n) scanf("%lld", &n)
#define scS(n) scanf("%s", &n)
#define mn(n, m) (n > m)?m:n
#define mx(n, m) (n < m)?m:n
#define S 123
using namespace std;
typedef long long LL;
int dirX[] = {1, 0, -1, 0, -1, 1, 1, -1};
int dirY[] = {0, 1, 0, -1, -1, 1, -1, 1};
int n, m, cnt, vis[S][S];
string WetLand[S];
string line;
int dfs(int i, int j){
if(i < 0 || j < 0 || i >= n || j >= m || WetLand[i][j] == 'L' || vis[i][j])return 0;
vis[i][j] = 1;
cnt++;
for(int z = 0; z < 8; z++){
int px = i+dirX[z];
int py = j+dirY[z];
dfs(px, py)+1;
}
return cnt;
}
int main(){
int t;
bool sp = false;
scI(t);
getchar(); getchar();
while(t--){
n = 0, m = 0;
if(sp)puts("");
sp = true;
while(getline(cin, line) && line.size() > 0){
if(!line.size())break;
if(line[0] == 'W' || line[0] == 'L'){
if(!m)m = line.size();
WetLand[n] = line;
n++;
}
else{
istringstream cinn(line);
int x, y;
cinn >> x; cinn >> y;
cnt = 0;
memset(vis, 0, sizeof(vis));
cout << dfs(x-1, y-1) << endl;
}
}
}
return 0;
}
No comments:
Post a Comment