蒟蒻求助:本机编译正常,洛谷编译失败

P2895 [USACO08FEB] Meteor Shower S

unsigned_char @ 2021-07-13 22:48:32

本机\mathit{Windows\ 7}\ \ \ \ \ \texttt{Dev\_C++}\ with\ \mathbb{GCC4.9.2}

代码:

#include<iostream>
#include<queue>

using std::cin;
using std::cout;
using std::queue;

class Cord
{
    public:
        int x;
        int y;
        int time;
};

int time[310][310];
queue<Cord> q;

int BFS()
{
    Cord tmp,next;
    tmp.x=1;
    tmp.y=1;
    tmp.time=0;
    time[1][1]=-1;
    for(int i=0;i<310;++i)
    {
        time[0][i]=-3;
        time[i][0]=-3;
    }
    q.push(tmp);
    while(!q.empty())
    {
        tmp=q.front();
        q.pop();
        if(time[tmp.x+1][tmp.y]==-2||time[tmp.x-1][tmp.y]==-2||time[tmp.x][tmp.y+1]==-2||time[tmp.x][tmp.y-1]==-2)
        {
            return tmp.time+1;
        }
        if(tmp.time+1<time[tmp.x+1][tmp.y])
        {
            next.x=tmp.x+1;
            next.y=tmp.y;
            next.time=tmp.time+1;
            time[tmp.x+1][tmp.y]=-1;
            q.push(next);
        }
        if(tmp.time+1<time[tmp.x-1][tmp.y])
        {
            next.x=tmp.x-1;
            next.y=tmp.y;
            next.time=tmp.time+1;
            time[tmp.x-1][tmp.y]=-1;
            q.push(next);
        }
        if(tmp.time+1<time[tmp.x][tmp.y+1])
        {
            next.x=tmp.x;
            next.y=tmp.y+1;
            next.time=tmp.time+1;
            time[tmp.x][tmp.y+1]=-1;
            q.push(next);
        }
        if(tmp.time+1<time[tmp.x][tmp.y-1])
        {
            next.x=tmp.x;
            next.y=tmp.y-1;
            next.time=tmp.time+1;
            time[tmp.x][tmp.y-1]=-1;
            q.push(next);
        }
    }
    return -1;
}

int main()
{
    int m,t,x,y;
    for(int i=0;i<310;++i)
    {
        for(int j=0;j<310;++j)
        {
            time[i][j]=-2;
        }
    }
    cin>>m;
    for(int i=0;i<m;++i)
    {
        cin>>x>>y>>t;
        x+=1;y+=1;
        if(time[x][y]<0||time[x][y]>t) time[x][y]=t;
        if(time[x+1][y]<0||time[x+1][y]>t) time[x+1][y]=t;
        if(time[x-1][y]<0||time[x-1][y]>t) time[x-1][y]=t;
        if(time[x][y+1]<0||time[x][y+1]>t) time[x][y+1]=t;
        if(time[x][y-1]<0||time[x][y-1]>t) time[x][y-1]=t;
    }
    cout<<BFS();
    return 0;
}

\mathit{Windows}\mathit{Linux}区别造成的吗?或者是\mathbb{GCC}版本区别吗?


by Allenliuyihang @ 2021-07-20 14:52:49

next改nxt试试


by unsigned_char @ 2021-07-26 21:37:25

@Allenliuyihang 跟next没关系,把time改成_time\colorbox{#52C410}{\color{white}\texttt{ AC }}


by Allenliuyihang @ 2021-07-27 07:54:03

啊,我的C++版本不同


|