Language: C

    #pragma comment(linker, "/STACK:102400000,102400000")  
    #include<iostream>  
    #include<vector>  
    #include<algorithm>  
    #include<cstdio>  
    #include<queue>  
    #include<stack>  
    #include<string>  
    #include<map>  
    #include<set>  
    #include<cmath>  
    #include<cassert>  
    #include<cstring>  
    #include<iomanip>  
    using namespace std;  
    #ifdef _WIN32  
    #define i64 __int64  
    #define out64 "%I64d\n"  
    #define in64 "%I64d"  
    #else  
    #define i64 long long  
    #define out64 "%lld\n"  
    #define in64 "%lld"  
    #endif  
    /************ for topcoder by zz1215 *******************/  
    #define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)  
    #define FF(i,a)        for( int i = 0 ; i < (a) ; i ++)  
    #define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)  
    #define S64(a)          scanf(in64,&a)  
    #define SS(a)           scanf("%d",&a)  
    #define LL(a)           ((a)<<1)  
    #define RR(a)           (((a)<<1)+1)  
    #define pb              push_back  
    #define pf              push_front  
    #define X               first  
    #define Y               second  
    #define CL(Q)           while(!Q.empty())Q.pop()  
    #define MM(name,what)   memset(name,what,sizeof(name))  
    #define MC(a,b)         memcpy(a,b,sizeof(b))  
    #define MAX(a,b)        ((a)>(b)?(a):(b))  
    #define MIN(a,b)        ((a)<(b)?(a):(b))  
    #define read            freopen("in.txt","r",stdin)  
    #define write           freopen("out.txt","w",stdout)  
      
    const int inf = 0x3f3f3f3f;  
    const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;  
    const double oo = 10e9;  
    const double eps = 10e-9;  
    const double pi = acos(-1.0);  
    const int maxn = 400;  
    const int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};  
      
    struct zz  
    {  
        int x,y;  
        int x2,y2;  
    }zx;  
      
    int sx,sy,ex,ey;  
    int n;  
    vector<zz>v;  
    vector<int>fx;  
    vector<int>fy;  
    map<int,int>mx;  
    map<int,int>my;  
      
    int ix,iy;  
    int a[maxn][maxn];  
    int dp[maxn][maxn][4];  
      
    void gao(int x,int y,int x2,int y2)  
    {  
        for(int i=x;i<=x2;i++)  
        {  
            a[i][y]++;  
        }  
        for(int i=y+1;i<=y2;i++)  
        {  
            a[x][i]++;  
            a[x2][i]++;  
        }  
        for(int i=x+1;i<x2;i++)  
        {  
            a[i][y2]++;  
        }  
        for(int i=x+1;i<x2;i++)  
        {  
            for(int j=y+1;j<y2;j++)  
            {  
                a[i][j]=2;  
            }  
        }  
        return ;  
    }  
      
    struct aa  
    {  
        int x;  
        int y;  
        int z;  
    }ax;  
      
    bool inq[maxn][maxn][4];  
      
    bool yes(int x,int y)  
    {  
        if(x>=0 && x<=ix && y>=0 && y<=iy)  
        {  
            return true;  
        }  
        return false;  
    }  
      
    int bfs()  
    {  
        ix+=2;  
        iy+=2;  
        for(int i=0;i<=ix;i++)  
        {  
            for(int j=0;j<=iy;j++)  
            {  
                for(int u=0;u<4;u++)  
                {  
                    dp[i][j][u]=inf;  
                    inq[i][j][u]=false;  
                }  
            }  
        }  
        queue<aa>q;  
        for(int i=0;i<4;i++)  
        {  
            dp[sx][sy][i]=0;  
            inq[sx][sy][i]=true;  
            ax.x = sx;  
            ax.y = sy;  
            ax.z = i;  
            q.push(ax);  
        }  
        aa now,to;  
        int temp;  
        while(!q.empty())  
        {  
            now = q.front();  
            q.pop();  
            for(int i=0;i<4;i++)  
            {  
                to.x = now.x + dir[i][0];  
                to.y = now.y + dir[i][1];  
                to.z = i;  
                if(yes(to.x,to.y) && a[to.x][to.y]<2)  
                if(to.z == now.z)  
                {  
                    temp = dp[now.x][now.y][now.z];  
                    if(temp < dp[to.x][to.y][to.z])  
                    {  
                        dp[to.x][to.y][to.z] = temp;  
                        if(!inq[to.x][to.y][to.z])  
                        {  
                            inq[to.x][to.y][to.z]=true;  
                            q.push(to);  
                        }  
                    }  
                }  
                else  
                {  
                    temp = dp[now.x][now.y][now.z]+1;  
                    if(temp<dp[to.x][to.y][to.z])  
                    {  
                        dp[to.x][to.y][to.z] = temp;  
                        if(!inq[to.x][to.y][to.z])  
                        {  
                            inq[to.x][to.y][to.z]=true;  
                            q.push(to);  
                        }  
                    }  
                }  
            }  
            inq[now.x][now.y][now.z] = false;  
        }  
        int re = inf;  
        for(int i=0;i<4;i++)  
        {  
            re = min(dp[ex][ey][i],re);  
        }  
        if(re == inf)  
        {  
            re = -1;  
        }  
        return re;  
    }  
      
    int start()  
    {  
        MM(a,0);  
        for(int i=0;i<v.size();i++)  
        {  
            gao(mx[v[i].x],my[v[i].y],mx[v[i].x2],my[v[i].y2]);  
        }  
        return bfs();  
    }  
      
    int main()  
    {  
        while(cin>>sx>>sy>>ex>>ey)  
        {  
            if(!sx && !sy && !ex && !ey) return 0;  
            cin>>n;  
            fx.clear();  
            fy.clear();  
            mx.clear();  
            my.clear();  
            v.clear();  
            for(int i=1;i<=n;i++)  
            {  
                SS(zx.x);SS(zx.y);  
                SS(zx.x2);SS(zx.y2);  
                v.pb(zx);  
                fx.pb(zx.x);  
                fx.pb(zx.x2);  
                fy.pb(zx.y);  
                fy.pb(zx.y2);  
            }  
            fx.pb(sx);  
            fx.pb(ex);  
            fy.pb(sy);  
            fy.pb(ey);  
            sort(fx.begin(),fx.end());  
            sort(fy.begin(),fy.end());  
            ix = 1;  
            for(int i=0;i<fx.size();i++)  
            {  
                mx[fx[i]] = ix;  
                ix+=2;  
            }  
            iy = 1;  
            for(int i=0;i<fy.size();i++)  
            {  
                my[fy[i]] = iy;  
                iy+=2;  
            }  
            sx = mx[sx];  
            ex = mx[ex];  
            sy = my[sy];  
            ey = my[ey];  
      
            cout<<start()<<endl;  
        }  
        return 0;  
    }  

Compiler output:
main.c:2:13: fatal error: iostream: No such file or directory
    2 |     #include<iostream>
      |             ^~~~~~~~~~
compilation terminated.