萌新妹子刚学OI 样例过不去2333

回复帖子

@Dorbmon 2019-10-13 22:58 回复

我都对着题解抄了,还是过不去,求巨佬帮忙!!!

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
inline long long read() {
    char ch = getchar(); long long x = 0, f = 1;
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    } while('0' <= ch && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    } return x * f;
}
bool rmap [1501][1501];
bool vis [1501][1501][3];
const int mv_x [4] = {0,0,1,-1};
const int mv_y [4] = {1,-1,0,0};
bool ok ;
int n,m;
void dfs (int x,int y,int lx,int ly) {
    if (ok) {
        return ;
    }
    if (vis [x][y][0] && (vis [x][y][1] != lx || vis [x][y][2] != ly)) {
        ok = true;
//      cout << x << " " << y << endl;
//      cout << lx << " " << ly << endl;
//      cout << vis [x][y][1] << " " << vis [x][y][2] << endl;
        return ;
    }
    vis [x][y][0] = true;vis [x][y][1] = lx,vis [x][y][2] = ly;
    for (int i = 0;i < 4;++ i) {
        int nx = (x + mv_x [i] + n) % n,ny = (y + mv_y [i] + m) % m;
        int tx = lx + mv_x [i],ty = ly + mv_y [i];
        if (rmap [nx][ny]) {
            continue ;
        }
        if (!vis [nx][ny][0] || vis [nx][ny][1] != tx || vis [nx][ny][2] != ty) {
            dfs (nx,ny,tx,ty);
        }
    }
}
int main(){
#ifndef ONLINE_JUDGE
    freopen ("shit.txt","r",stdin);
#endif 
#ifdef ONLINE_JUDGE
#endif
    while (cin >> n >> m) {
        int s_x,s_y;
        memset (rmap,0,sizeof rmap);
        memset (vis,0,sizeof vis);
        for (int i = 0;i < n;++ i) {
            for (int j = 0;j < m;++ j) {
                char ch;cin >> ch;
                if (ch == '#') {
                    rmap [i][j] = true;
                }
                if (ch == 'S') {
                    s_x = i,s_y = j;
                }
            }
        }
        ok = false;
        dfs (s_x,s_y,s_x,s_y);
        if (ok) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
    return 0;
}

求助!!!!!

反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。