10936 - Land surveyor's job

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

trulo17
Learning poster
Posts: 62
Joined: Mon Jan 24, 2005 6:12 am
Location: Lima,Peru

10936 - Land surveyor's job

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

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan
your angel will be a strange figture in some situation

like > 2*Pi

polone
New poster
Posts: 43
Joined: Sun May 08, 2005 2:31 am
Location: Taiwan
unn...I recieve Wa too orz

luishhh
New poster
Posts: 26
Joined: Mon Oct 25, 2004 8:11 pm
Location: Spain
you shouldn't add A[n].distance to total
try it now
"From lost to the river" --> Spanish quote

rage_true
New poster
Posts: 8
Joined: Mon Sep 13, 2004 5:25 pm
2 trulo17
Why you add to angel pi?
>>

trulo17
Learning poster
Posts: 62
Joined: Mon Jan 24, 2005 6:12 am
Location: Lima,Peru
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)

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
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

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:
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.

baodog
Experienced poster
Posts: 202
Joined: Wed Jul 04, 2007 6:53 am
Yes, make sure you add Pi.. it's the external angle.
Last edited by baodog on Wed Oct 10, 2007 10:48 am, edited 1 time in total.

baodog
Experienced poster
Posts: 202
Joined: Wed Jul 04, 2007 6:53 am
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.

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

Re: 10936 - Land surveyor's job

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?