【题目描述】
你在一个 n 行 m 列的网格迷宫中,迷宫的每一格要么为空,要么有一个障碍。
你当前在第 r 行第 c 列(保证该格子为空)。每次移动你可以向上下左右任意一个方向移动一格,前提是不能走到障碍上,也不能超出迷宫的边界。
你向左移动的次数不能超过 x 次,向右不能超过 y 次。
问在这种情况下,对于每个格子,是否存在一种移动方案让你走到它。
输出有多少个格子存在移动方案让你走到它。【输入描述】
第一行两个正整数 n,m 。
第二行两个正整数 r,c ,保证 1≤r≤n ,1≤c≤m 。
第三行两个整数 x,y ,保证 0≤x,y≤109。
接下来 n 行,每行一个长度为 m 的字符串,
第 i 行第 j 个字符表示迷宫第 i 行第 j 列的格子,
字符为`.` 表示格子为空,字符为`*` 表示格子上有一个障碍。【输出描述】
输出一个数,表示有多少个格子存在移动方案让你走到它。
【样例】
示例1
输入
4 5
3 2
1 2
.....
.***.
...**
*....
输出
10示例2
输入
4 4
2 2
0 1
....
..*.
....
....
输出
7
【源代码】
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct Node {
int x,y;
int left,right;
Node(){}
Node(int x,int y,int left,int right):x(x),y(y),left(left),right(right){}
};
int n,m;
char G[N][N];
bool vis[N][N];
int Left,Right,res;
void bfs(int sx,int sy) {
res=0;
vis[sx-1][sy-1]=true;
queue<Node> Q;
Q.push(Node(sx-1,sy-1,0,0));
while(!Q.empty()) {
Node now=Q.front();
Q.pop();
res++;
int left=now.left;
int right=now.right;
for(int i=0; i<4; i++) {
int x=now.x+dx[i];
int y=now.y+dy[i];
if(x>=0&&x<n&&y>=0&&y<m&&!vis[x][y]&&G[x][y]!='*'){
if(i==0||i==1) {
Q.push(Node(x,y,now.left,now.right));
vis[x][y]=true;
}
else if(i==2&&left<Left) {
left++;
Q.push(Node(x,y,now.left+1,now.right));
vis[x][y]=true;
}
else if(i==3&&now.right<Right) {
right++;
Q.push(Node(x,y,now.left,now.right+1));
vis[x][y]=true;
}
}
}
}
}
int main() {
int sx,sy;
scanf("%d%d",&n,&m);
scanf("%d%d",&sx,&sy);
scanf("%d%d",&Left,&Right);
getchar();
for(int i=0; i<n; i++)
scanf("%s",G[i]);
bfs(sx,sy);
printf("%d\n",res);
return 0;
}