Page 1 of 1

10936 - Land surveyor's job

Posted: Sun Oct 16, 2005 8:13 am
by trulo17

Code: Select all

#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
struct point
{
    double angle,distance;
};
int main()
{
    int n,i,j,L;
    char s[15];
    double pi=2*acos(0.0),degree,minute,second,angle,x1,y1,x2,y2,xt,yt,total;
    point A[1000];
    for(;;)
    {
        scanf("%d",&n);
        if(n==0)
            break;
        for(i=0;i<n;++i)
        {
            scanf("%lf%s",&A[i].distance,s);
            for(j=0,L=strlen(s);j<L;++j)
                if(!isdigit(s[j]))
                    s[j]=' ';
            sscanf(s,"%lf%lf%lf",&degree,&minute,&second);
            A[i].angle=(degree+minute/60+second/3600)*pi/180;
        }
        for(i=2,angle=pi,x1=0.0,y1=0.0,x2=A[1].distance,y2=0.0,total=A[0].distance+A[1].distance;i<=n;total+=A[i].distance,++i)
        {
            angle-=A[i-1].angle;
            xt=x2+A[i-1].distance*cos(angle);
            yt=y2+A[i-1].distance*sin(angle);
            x1=x2;
            y1=y2;
            x2=xt;
            y2=yt;
            //printf("%.4lf %.4lf %.4lf\n",xt,yt,angle);
            angle+=pi;
        }
        //printf("%.4lf %.4lf\n",sqrt(xt*xt+yt*yt),total);
        if(sqrt(xt*xt+yt*yt)*1000<total)
            puts("Acceptable");
        else
            puts("Not acceptable");
    }
}
what's wrong with the code above? thx in advance

Posted: Mon Oct 17, 2005 1:52 pm
by polone
your angel will be a strange figture in some situation

like > 2*Pi

Posted: Mon Oct 17, 2005 2:58 pm
by polone
unn...I recieve Wa too orz

Posted: Mon Oct 17, 2005 3:48 pm
by luishhh
you shouldn't add A[n].distance to total
try it now

Posted: Tue Oct 18, 2005 12:07 am
by rage_true
2 trulo17
Why you add to angel pi?
>>

Posted: Tue Oct 18, 2005 2:22 am
by trulo17
rage_true wrote
:2 trulo17
Why you add to angel pi?
>> angle+=pi;
this way i change the current direction to the opossite, this is necessary in my algorithm to measure the correct angle(due to the problems conditions)

Posted: Wed Nov 30, 2005 12:02 am
by Darko
Just to join the party, here's more WA code, now in Java! :)

Code: Select all

[EDIT] Misinterpreted the problem statement, added PI to the angle and got accepted (no other changes) - hope it helps someone
No idea what's wrong with this. I walk from (0,0) changing directions as given, in the end I just check how far I am from (0,0). Sounds simple, but I am missing something.

Darko

Posted: Tue Aug 29, 2006 3:13 am
by sclo
I got AC after i added pi to angle too.

It means the angle we need to turn at each station is pi + the angle given.

Posted: Wed Oct 10, 2007 3:01 am
by baodog
Yes, make sure you add Pi.. it's the external angle.

Posted: Wed Oct 10, 2007 10:47 am
by baodog
To Trulo: Your first distance should be A[0].dist not A[1].dist Also your array bounds appear to be too small to handle the input.

Re: 10936 - Land surveyor's job

Posted: Fri Sep 28, 2012 9:59 am
by lnr
What's wrong with this code?

Code: Select all

    #include<cstdio>
    #include<cmath>
    #include<cctype>
    #include<cstring>
    struct point
    {
        double angle,distance;
    };
    int main()
    {
        int n,i,j,L;
        char s[15];
        double pi=2*acos(0.0),degree,minute,second,angle,x1,y1,x2,y2,xt,yt,total;
        point A[1000];
        for(;;)
        {
            scanf("%d",&n);
            if(n==0)
                break;
            for(i=0;i<n;++i)
            {
                scanf("%lf%s",&A[i].distance,s);
                for(j=0,L=strlen(s);j<L;++j)
                    if(!isdigit(s[j]))
                        s[j]=' ';
                sscanf(s,"%lf%lf%lf",&degree,&minute,&second);
                A[i].angle=(degree+minute/60+second/3600)*pi/180;
            }
            for(i=2,angle=pi,x1=0.0,y1=0.0,x2=A[1].distance,y2=0.0,total=A[0].distance+A[1].distance;i<=n;total+=A[i].distance,++i)
            {
                angle-=A[i-1].angle;
                xt=x2+A[i-1].distance*cos(angle);
                yt=y2+A[i-1].distance*sin(angle);
                x1=x2;
                y1=y2;
                x2=xt;
                y2=yt;
                //printf("%.4lf %.4lf %.4lf\n",xt,yt,angle);
                angle+=pi;
            }
            //printf("%.4lf %.4lf\n",sqrt(xt*xt+yt*yt),total);
            if(sqrt(xt*xt+yt*yt)*1000<total)
                puts("Acceptable");
            else
                puts("Not acceptable");
        }
        return 0;
    }
It's others(trulo17) code of this forum, i was just trying with this code, i can't get any clue. Can someone please give some clue for the problem with this code? Can someone post some input output for this code?

I can't understand the problem well. Why is PI added with angle every time? How does PI come here?