为什么蜜汁RE??

P2895 [USACO08FEB] Meteor Shower S

Blackie @ 2016-10-23 14:32:38

wk写了一个小时结果蜜汁RE了。。

炒鸡不爽还找不到哪里错了。。。

求大神看看!

#include<iostream>
using namespace std;

const int n=300;

int m,x,y,t,head=1,tail=1;
short int map[n+5+1][n+5+1];
bool notSafe[n+5+1][n+5+1],cannotPass[n+5+1][n+5+1],visited[n+5+1][n+5+1];
struct node
{
    int x;
    int y;
}point[n+5+1][n+5+1],que[93026];

void push(node a)
{
    que[tail]=a;
    tail++;

    return;
}

node pop()
{
    head++;
    return que[head-1];
}

bool empty()
{
    if(head==tail)
        return true;
    return false;
}

void bfs()
{
    node top;

    while(!empty())
    {
        top=pop();
        visited[top.x][top.y]=true;

        if(notSafe[top.x][top.y]==false)
        {
            cout<<map[top.x][top.y];
            return;
        }

        if(cannotPass[top.x-1][top.y]==false && top.x-1>=0 && visited[top.x-1][top.y]==false)
            push(point[top.x-1][top.y]);
        if(cannotPass[top.x+1][top.y]==false && top.x+1<=n+5 && visited[top.x+1][top.y]==false)
            push(point[top.x+1][top.y]);
        if(cannotPass[top.x][top.y-1]==false && top.y-1>=0 && visited[top.x][top.y-1]==false)
            push(point[top.x][top.y-1]);
        if(cannotPass[top.x][top.y+1]==false && top.y+1<=n+5 && visited[top.x][top.y+1]==false)
            push(point[top.x][top.y+1]);
    }

    cout<<-1;

    return;
}

void safe()
{
    notSafe[x][y]=true;
    if(x-1>=0)
        notSafe[x-1][y]=true;
    if(x+1<=n+5)
        notSafe[x+1][y]=true;
    if(y-1>=0)
        notSafe[x][y-1]=true;
    if(y+1<=n+5)
        notSafe[x][y+1]=true;

    return;
}

void pass()
{
    if(map[x][y]>=t)
        cannotPass[x][y]=true;
    if(x-1>=0 && map[x-1][y]>=t)
        cannotPass[x-1][y]=true;
    if(x+1<=n+5 && map[x+1][y]>=t)
        cannotPass[x+1][y]=true;
    if(y-1>=0 && map[x][y-1]>=t)
        cannotPass[x][y-1]=true;
    if(y+1<=n+5 && map[x][y+1]>=t)
        cannotPass[x][y+1]=true;

    return;
}

void read()
{
    int i,j;

    std::ios::sync_with_stdio(false);

    for(i=0; i<=2*(n+5); i++)
        for(j=0; j<=min(i,n+5); j++)
            if(i-j<=n+5 && i-j>=0)
                map[i-j][j]=i;
    for(i=0; i<=n+5; i++)
        for(j=0; j<=n+5; j++)
        {
            point[i][j].x=i;
            point[i][j].y=j;
        }

    cin>>m;
    for(i=1; i<=m; i++)
    {
        cin>>x>>y>>t;

        safe(); pass();
    }

    if(cannotPass[0][0]==true)
    {
        cout<<-1;
        return;
    }

    push(point[0][0]);
    bfs();

    return;
}

int main()
{
    read();
    return 0;
}

感觉数组大小还开大了以后怎么还RE。。

不爽。。


|