https://ac.nowcoder.com/acm/contest/332/J
C++版本一
题解:BFS
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,r,c,x,y;
int ans,cnt,flag,temp;
int vis[N][N];
int dir[][2]={1,0,0,1,-1,0,0,-1};
char str[N][N];
struct node{
int x,y;
int lc,rc;
}tmp,f;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
scanf("%d%d%d%d%d%d",&n,&m,&r,&c,&x,&y);
for(int i=1;i<=n;i++)
scanf("%s",str[i]+1);
f.x=r;
f.y=c;
f.lc=0;
f.rc=0;
vis[r][c]=1;
ans++;
queue<node>q;
q.push(f);
while(!q.empty()){
f=q.front();
q.pop();
for(int i=0;i<4;i++){
tmp.x=f.x+dir[i][0];
tmp.y=f.y+dir[i][1];
tmp.lc=f.lc;
tmp.rc=f.rc;
if(i==1)
tmp.rc++;
if(i==3)
tmp.lc++;
if(tmp.x<1||tmp.x>n||tmp.y<1||tmp.y>m)
continue;
if(tmp.lc>x||tmp.rc>y)
continue;
if(str[tmp.x][tmp.y]=='*'||vis[tmp.x][tmp.y])
continue;
vis[tmp.x][tmp.y]=1;
ans++;
q.push(tmp);
}
}
cout << ans << endl;
//cout << "Hello world!" << endl;
return 0;
}
似乎被HACK了
6 9
6 6 5 10
*********
**..*...*
***.*.*.*
......*.*
.******.*
........*