bfs test8 WA,求调
  • 板块CF1063B Labyrinth
  • 楼主Suboil
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/14 15:59
  • 上次更新2023/11/2 20:57:43
查看原帖
bfs test8 WA,求调
1026350
Suboil楼主2023/9/14 15:59

Test8 data

2000 2000
1 2
1000000000 1000000000
*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*.....*......
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
typedef long long lg;
struct POINT{
    int x,y;lg ll,rr;
}que[N * 4];
int n,m,r,c,x,y,cnt = 0;
char ditu[N][N];int vis[N][N];
int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};

void bfs() {
    int head = 0,tail = 1;
    que[1] = {r,c,0,0};
    vis[r][c] = 1;
    int flag;
    while(head < tail) {    
        head++;
        for(int i = 0;i < 4;i++) {
            flag = 0;
            int nx = que[head].x + dir[i][0],ny = que[head].y + dir[i][1];
            if(nx < 1 || ny < 1 || nx > n || ny > m || vis[nx][ny] || ditu[nx][ny] == '*') continue;

            if(i == 2) {
                if(que[head].ll >= x) continue;
                else flag = 2;
            }

            if(i == 3) {
                if(que[head].rr >= y) continue;
                else flag = 3;
            }

            tail++;
            vis[nx][ny] = 1;
            if(flag == 2) que[tail] = {nx,ny,que[head].ll + 1,que[head].rr};   
            else if(flag == 3) que[tail] = {nx,ny,que[head].ll,que[head].rr + 1};   
            else {
                que[tail] = {nx,ny,que[head].ll,que[head].rr};   
            }
        
        }
    }
}


int main(){
    cin >> n >> m >> r >> c >> x >> y;
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            cin >> ditu[i][j];
        }
    }

    bfs();
    

    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            if(vis[i][j]) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


2023/9/14 15:59
加载中...