ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1202. Rectangles Travel

Please have a look at this - i got Comp.ERror not less than 10 times
Posted by Vladimir Milenov Vasilev 13 Apr 2002 15:49
Hi!
Here is my source - I compiled it on Visual C++ and it is OK - but
here got "compilation Error". Could anyone explain me why???



#include <stdio.h>
long x1,x2,y1,y2,ymin,ymax,n,i,posy,disttt;


void main()
{
    bool boo;
    boo=false;
    scanf("%ld",&n);
    scanf("%ld%ld%ld%ld",&x1,&y1,&x2,&y2);
    disttt=0;
    posy=1;
    ymin=y1;
    ymax=y2;
    for(i=1;i<n;i++)
    {
        scanf("%ld%ld%ld%ld",&x1,&y1,&x2,&y2);
        if(y1>=ymax-1||y2<=ymin+1)
        {
            printf("-1\n");
            boo=true;;
        }
        if (posy<=y1)
        {
            disttt+=(y1+1-posy);
            posy=y1+1;
        }
        else if (posy>=y2)
        {
            disttt+=posy-y2+1;
            posy=y2-1;
        }
        ymin=y1;
        ymax=y2;
    }
    disttt+=x2-2;
    if (posy>y2-1) disttt+=posy+1-y2;
    else if(posy<y2-1) disttt+=y2-1-posy;
    if (boo==false) printf("%ld\n",disttt);
}



Thanks!
Re: Please have a look at this - i got Comp.ERror not less than 10 times
Posted by Tiberiu Danet 27 Aug 2002 18:08
Try replacing y1 with y1_ and y2 with y2_.
You will get accepted.
The same thing happened to me.
Re: Please have a look at this - i got Comp.ERror not less than 10 times
Posted by Band of Brothers 21 Dec 2002 07:09
Do not use bool,the compiler may not support this
who can tell me what the difference is
Posted by November Rain 18 Jul 2004 02:07
I think my code is right,but it was getting wa wa all the time.
So I started to change it.
I saw the code above,so I changed mine more and more like that.
But a surprising thing ,my code is even equal to the code above,
but it got accepted,but my still wa.
I wonder..............

my code
#include<iostream>
#include<string>
#include<memory>
using namespace std;

int main(void)
{
    long n;
    cin>>n;
       long nowy=1,i,maxy,miny,x1,y1,x2,y2;
    long dist=0;
    cin>>x1>>miny>>x2>>maxy;
    bool ok=true;
    for(i=1;i<n;++i){
         cin>>x1>>y1>>x2>>y2;
        if(y1>=maxy-1||y2<=miny+1){
            ok=false;
            break;
        }
           if(y1>=nowy){
               dist+=y1+1-nowy;
               nowy=y1+1;
        }
        else if(y2<=nowy){
              dist+=nowy-y2+1;
            nowy=y2-1;
        }
        miny=y1;
        maxy=y2;
    }
    if(ok){
        dist+=x2-2;
        //dist+=abs(y2-1-nowy);
        if(nowy>y2-1)dist+=nowy+1-y2;
        else if(nowy<y2-1)dist+=y2-1-nowy;
        cout<<dist<<endl;
    }
    else cout<<"-1"<<endl;
    return 0;
}
Re: Please have a look at this - i got Comp.ERror not less than 10 times
Posted by cpc 15 Jun 2009 15:21
Now this code get AC.