为什么RE到20分。。。求帮助。。。

P1746 离开中山路

洛必达法则 @ 2018-12-22 16:30:22

#include<bits/stdc++.h>
using namespace std;
inline long long read();
bool mp[1010][1010];
bool book[1010][1010];
struct point
{
    long long x,y;
    point(long long x=0,long long y=0):x(x),y(y){}
    inline double dist(const point b)
    {
        long double p=(this->x-b.x)*(this->x-b.x)+(this->y-b.y)*(this->y-b.y);
        return sqrt(p);
    }
    inline void bookit()
    {
        book[this->x][this->y]=true;
    }
    inline bool booked()
    {
        return book[this->x][this->y];
    }
    inline bool can()
    {
        return !mp[this->x][this->y];
    }
    inline double dist_pow2(const point b)
    {
        long double p=(this->x-b.x)*(this->x-b.x)+(this->y-b.y)*(this->y-b.y);
        return p;
    }
    inline void input()
    {
        this->x=read();
        this->y=read();
        return;
    }
    inline void print()
    {
        printf("(%lld,%lld)\n",this->x,this->y);
        return;
    }
    point operator = (const point b)
    {
        this->x=b.x;
        this->y=b.y;
        return (*this);
    }
    point operator + (const point b)
    {
        point c;
        c.x=b.x+this->x;
        c.y=b.y+this->y;
        return c;
    }
    point operator += (const point b)
    {
        (*this)=(*this)+b;
        return (*this);
    }
    point operator - (const point b)
    {
        point c;
        c.x=b.x+this->x-b.x;
        c.y=b.y+this->y-b.y;
        return c;
    }
    point operator -= (const point b)
    {
        (*this)=(*this)-b;
        return (*this);
    }
    bool operator == (const point b) const
    {
        if(this->x==b.x&&this->y==b.y)
        {
            return true;
        }
        return false;
    }
    bool operator != (const point b) const
    {
        return (!((*this)==b));
    }
};
point up(0,-1),dn(0,1),l(-1,0),r(1,0);
struct step
{
    point now;
    long long passed;
    bool operator == (const step b)
    {
        if(this->now!=b.now)
        {
            return false;
        }
        if(this->passed!=b.passed)
        {
            return false;
        }
        return true;
    }
};
queue<step> que;
long long n;
point st,ed;
bool get_bool();

by 洛必达法则 @ 2018-12-22 16:31:13

int main()
{
    n=read();
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=n;j++)
        {
            mp[i][j]=get_bool();
        }
    }
    st.input();
    ed.input();
    if(st==ed)
    {
        printf("0\n");
        exit(0);
    }
    if(true)
    {
        step young;
        young.now=st;
        young.passed=0;
        que.push(young);
        young.now.bookit();
    }
    while(!que.empty())
    {
        for(long long i=1;i<=4;i++)
        {
            if(i==1)
            {
                step young;
                young.now=que.front().now+up;
                young.passed=que.front().passed+1;
                if(!young.now.booked())
                {
                    if(young.now.can())
                    {
                        if(young.now==ed)
                        {
                            printf("%lld\n",young.passed);
                            exit(0);
                        }
                        que.push(young);
                        young.now.bookit();
                    }
                }
            }
            if(i==2)
            {
                step young;
                young.now=que.front().now+dn;
                young.passed=que.front().passed+1;
                if(!young.now.booked())
                {
                    if(young.now.can())
                    {
                        if(young.now==ed)
                        {
                            printf("%lld\n",young.passed);
                            exit(0);
                        }
                        que.push(young);
                        young.now.bookit();
                    }
                }
            }
            if(i==3)
            {
                step young;
                young.now=que.front().now+l;
                young.passed=que.front().passed+1;
                if(!young.now.booked())
                {
                    if(young.now.can())
                    {
                        if(young.now==ed)
                        {
                            printf("%lld\n",young.passed);
                            exit(0);
                        }
                        que.push(young);
                        young.now.bookit();
                    }
                }
            }
            if(i==4)
            {
                step young;
                young.now=que.front().now+r;
                young.passed=que.front().passed+1;
                if(!young.now.booked())
                {
                    if(young.now.can())
                    {
                        if(young.now==ed)
                        {
                            printf("%lld\n",young.passed);
                            exit(0);
                        }
                        que.push(young);
                        young.now.bookit();
                    }
                }
            }
        }
        que.pop();
    }
    return 0;
}
bool get_bool()
{
    char p;
    while(true)
    {
        p=getchar();
        if(p=='0')
        {
            return false;
        }
        if(p=='1')
        {
            return true;
        }
    }
}
inline long long read()
{
    long long val=0,flag=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9'))
    {
        ch=getchar();
    }
    while(ch=='-')
    {
        flag=-flag,ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        val=(val << 1)+(val << 3)+ch-'0',ch=getchar();
    }
    return val*flag;
}

|