是数据错了???(蒟蒻的疑问

P2385 [USACO07FEB] Bronze Lilypad Pond B

Timing @ 2019-02-27 14:56:28

RT

我的第7个点和第12个点错了,求大神指教QAQ

#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
int n,m,ans,mp[50][50],dx[10],dy[10];
int a,b,sx,sy,tx,ty;;
bool vis[50][50];
struct walk{int x,y,step;};
queue<walk>q;
inline int bfs(){
//  memset(vis,0,sizeof(vis));
    q.push((walk){sx,sy,0});
    vis[sx][sy]=1;
    while(!q.empty()){
        int x=q.front().x,y=q.front().y,cnt=q.front().step;
        if(x==tx&&y==ty)return cnt;
        q.pop();
        for(int i=1;i<=8;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<1||nx>m||ny<1||ny>n)continue;
            if(vis[nx][ny]==1||mp[nx][ny]==0||mp[nx][ny]==2)continue;
            if(nx==tx&&y==ty)return cnt+1;
            q.push((walk){nx,ny,cnt+1});
            vis[nx][ny]=1;
        }
    }
}
int main(){
    m=read();n=read();a=read();b=read();
    for(int i=1;i<=m;++i)
      for(int j=1;j<=n;++j){
        mp[i][j]=read();
        if(mp[i][j]==3)sx=i,sy=j;
        if(mp[i][j]==4)tx=i,ty=j;
    }
    if(a!=b){
        dx[1]=a,dy[1]=b;
        dx[2]=a,dy[2]=-b;
        dx[3]=-a,dy[3]=b;
        dx[4]=-a,dy[4]=-b;
        dx[5]=b,dy[5]=a;
        dx[6]=b,dy[6]=-a;
        dx[7]=-b,dy[7]=a;
        dx[8]=-b,dy[8]=-a;
    }
    cout<<bfs();
    return 0;
}

第7个点:

  • 输入:
  • 4 5 1 2
  • 0 1 1 1 1
  • 2 1 1 1 1
  • 0 1 4 2 1
  • 0 3 1 1 0

  • 输出:
  • 4

by Timing @ 2019-02-27 18:35:28

汗。。。数据没问题,但不知道那错了


by Timing @ 2019-02-27 18:39:37

问题已解决。。。我把ny打成了y,,,桑心


|