267  Of(f) Course!
Moderator: Board moderators
My Observation
After about 10 submission, i finally get Accepted(PE).....
My observations:
1. input speeds are greater than zero
2. there is always solutions that lead your plane to fly along the desired direction, although you may flying backwards. (consider the set of data '100 270 0 1', you can never fly the direction you want, even backward...)
3. Take care if you are using math division. Division by a small number may lead to round off error.
4. Take care about presentation of '0.0001' and '359.999'
Personally, i think this question is not so good. Too much on presentation requirement rather than algorithm.... may be i am stupid...
My observations:
1. input speeds are greater than zero
2. there is always solutions that lead your plane to fly along the desired direction, although you may flying backwards. (consider the set of data '100 270 0 1', you can never fly the direction you want, even backward...)
3. Take care if you are using math division. Division by a small number may lead to round off error.
4. Take care about presentation of '0.0001' and '359.999'
Personally, i think this question is not so good. Too much on presentation requirement rather than algorithm.... may be i am stupid...
267  Of(f) Course!
i'm trying to calculate ground_speed, but for some reason, it doesn't work correctly
please help me
please help me
Code: Select all
#include <iostream.h>
#include <stdio.h>
#include <math.h>
#ifndef ONLINE_JUDGE
#include <fstream.h>
ifstream fcin("267.txt");
#define cin fcin
#endif
#define pi 3.1415926535897932384626433832795
int main()
{
double wind_speed, wind_direction, desired_course,air_speed;
double AIRCRAFT_HEADING,GROUND_SPEED;
cin>>wind_speed;
int n=0;
while(!cin.eof())
{
cin>>wind_direction>>desired_course>>air_speed;
if(n++>0)printf("\n");
printf("WIND SPEED %0.2lf\n",wind_speed);
printf("WIND DIRECTION %0.2lf\n",wind_direction);
printf("DESIRED COURSE %0.2lf\n",desired_course);
printf("TRUE AIRSPEED %0.2lf\n",air_speed);
//#ifndef ONLINE_JUDGE
AIRCRAFT_HEADING = 0;
GROUND_SPEED = 0;
//#endif
if(wind_direction >=180.00)
wind_direction = 180;
else
wind_direction += 180;
double x=air_speed*sin(desired_course*(pi/180))+wind_speed*sin(wind_direction*(pi/180));
double y=air_speed*cos(desired_course*(pi/180))+wind_speed*cos(wind_direction*(pi/180));
GROUND_SPEED = sqrt(x*x+y*y);
printf("AIRCRAFT HEADING %0.2lf\n",AIRCRAFT_HEADING);
printf("GROUND SPEED %0.2lf\n",GROUND_SPEED);
cin>>wind_speed;
}
return 0;
}
267
I solved this problem and it was accepted except I had to make it output what I think is the wrong answer.
WIND SPEED 15.00
WIND DIRECTION 290.00
DESIRED COURSE 260.00
TRUE AIRSPEED 100.00
AIRCRAFT HEADING 264.30
GROUND SPEED 86.73
Looking at that example, it says the wind is moving at 290 degrees and the desired course is 260. So, I would think the aircraft heading would be somewhere less than 260 to compensate for the wind in the opposite direction. Sure enough, the numbers look fine that way to me except if I find that the aircraft heading should be, say, 10 degrees clockwise of the desired course, the actual solution is 10 degrees counterclockwise. Which would cause both the wind and the aircraft heading to be moving the plane counterclockwise of it's desired course. It's adding up instead of cancelling out. At least that's how I'm interepreting the question.
WIND SPEED 15.00
WIND DIRECTION 290.00
DESIRED COURSE 260.00
TRUE AIRSPEED 100.00
AIRCRAFT HEADING 264.30
GROUND SPEED 86.73
Looking at that example, it says the wind is moving at 290 degrees and the desired course is 260. So, I would think the aircraft heading would be somewhere less than 260 to compensate for the wind in the opposite direction. Sure enough, the numbers look fine that way to me except if I find that the aircraft heading should be, say, 10 degrees clockwise of the desired course, the actual solution is 10 degrees counterclockwise. Which would cause both the wind and the aircraft heading to be moving the plane counterclockwise of it's desired course. It's adding up instead of cancelling out. At least that's how I'm interepreting the question.
obviously wind direction 290 means wind *comes from* 290.
this is why ground speed is less than true air speed. (wind comes from the front, not back)
so one would expect aircraft heading to always be between desired course and wind speed. (unless the difference is greater than 180 then it's not)
best regards.
this is why ground speed is less than true air speed. (wind comes from the front, not back)
so one would expect aircraft heading to always be between desired course and wind speed. (unless the difference is greater than 180 then it's not)
best regards.
We never perform a computation ourselves, we just hitch a ride on the great Computation that is going on already. Tomasso Toffoli
Invalid Memory reference...
Anyone know what this means?
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
I think it's in reference to the way I terminated my input loop, but I can't figure out how else to do it. I've tried while(!cin.eof()) and while(cin) but neither seems to work....any ideas?
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
I think it's in reference to the way I terminated my input loop, but I can't figure out how else to do it. I've tried while(!cin.eof()) and while(cin) but neither seems to work....any ideas?

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
Could anyone tell me , why this program got WA ?
I'ii be very greatful for any IO sample, on which ths program fails... (with correct output) )
Best reagrds
DM
I'ii be very greatful for any IO sample, on which ths program fails... (with correct output) )
Best reagrds
DM
Code: Select all
#include <stdio.h>
#include <math.h>
#define RAD (180.0 / PI)
#define DEG (PI / 180.0)
int main(void)
{
double WS,alfa2,alfa1,AS,x,x1,x2,beta,ASx,ASy,delta,alfa,PI;
int first = 1;
PI = acos(1.0);
while(scanf("%lf %lf %lf %lf",&WS,&alfa2,&alfa1,&AS) == 4)
{
if(first)
first = 0;
else
printf("\n");
printf("WIND SPEED %.2lf\n",WS);
printf("WIND DIRECTION %.2lf\n",alfa2);
printf("DESIRED COURSE %.2lf\n",alfa1);
printf("TRUE AIRSPEED %.2lf\n",AS);
x1 = beta = fabs(alfa1  alfa2);
x2 = RAD*asin(WS/AS*sin(beta*DEG));
beta = alfa1 + x2;
if(beta < 0.0) beta += 360.0;
while(beta >= 360.0) beta = 360.0;
if(x2 < 0.0) x2 += 360.0;
if(x2 >= 180.0) x2 = 180.0;
x2 *= DEG;
x = WS*sin(DEG*x1  x2)/sin(x2);
if((fabs(beta) < 0.005)  (beta >= 359.995)) beta = 0.0;
if(fabs(x) < 0.005) x = 0.0;
printf("AIRCRAFT HEADING %.2lf\n",beta);
printf("GROUND SPEED %.2lf\n",x);
}
return 0;
}
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)

 Learning poster
 Posts: 83
 Joined: Wed Feb 27, 2002 2:00 am
 Location: Taiwan
I found that the input speeds may be negative.
Could somebody tell me what's the output for the following inputs?
thx
Could somebody tell me what's the output for the following inputs?
Code: Select all
15 110 260 100
23 294 319 19
Hi Dominik,
Could be undefined if sin(x2) is 0;
INTPUT
OUTPUT
Can't confirm because I myself haven't gotten AC.
Code: Select all
x = WS*sin(DEG*x1  x2)/sin(x2);
INTPUT
Code: Select all
15.0 260.0 260.0 101.73
Code: Select all
WIND SPEED 15.00
WIND DIRECTION 260.00
DESIRED COURSE 260.00
TRUE AIRSPEED 101.73
AIRCRAFT HEADING 260.00
GROUND SPEED 86.73
Hi All
I think I have a problem of understanding the output. Can anyone help?
For the second sample input
15.0 270.0 135.0 200.0
We have the following diagram
15 (wind)
>
\
\ 200 (plane relative to air)
\
Since we know the velocity of plane relative to ground = velocity of plane relative to wind + velocity of wind.
The speed of the plane should be sqrt((15 + 200 cos45)^2 + (200 sin45)^2) = 210.87????
Obviously, that's not the sample output.
Can anyone please explain to me which bit did I get it wrong?
Thanks
I think I have a problem of understanding the output. Can anyone help?
For the second sample input
15.0 270.0 135.0 200.0
We have the following diagram
15 (wind)
>
\
\ 200 (plane relative to air)
\
Since we know the velocity of plane relative to ground = velocity of plane relative to wind + velocity of wind.
The speed of the plane should be sqrt((15 + 200 cos45)^2 + (200 sin45)^2) = 210.87????
Obviously, that's not the sample output.
Can anyone please explain to me which bit did I get it wrong?
Thanks

 Learning poster
 Posts: 63
 Joined: Tue Mar 07, 2006 6:51 pm
 Location: india
WA:267
i solved the prob 267 but i m getting WA plz help me .
here is my code ....
here is my code ....
Code: Select all
#include<stdio.h>
#include<math.h>
main()
{
double vwg,thetaw,thetar,vaw,theta,alpha,phi,v,p,q,r,s;
while(scanf("%lf%lf%lf%lf",&vwg,&thetaw,&thetar,&vaw)!=EOF)
{ p=vwg;
q=thetaw;
r=thetar;
s=vaw;
thetaw = thetaw  180.00;
if(thetaw<0)
thetaw=360.00+thetaw;
if(thetaw > thetar)
theta=thetawthetar;
else
theta=thetarthetaw;
if(theta > 180)
theta=360theta;
alpha=theta+(180/3.14)*asin((vwg/vaw)*sin((3.14*theta)/180));
if(thetaw > thetar)
{
if(thetawthetar > 180)
phi=thetaw+alpha180;
else
phi=thetawalpha;
if(phi<0)
phi=360+phi;
}
else
{
if(thetar  thetaw > 180)
phi=360+thetawalpha;
else
phi=alpha+ thetaw;
if(phi>360)
phi=phi  360;
}
v=sqrt(vwg*vwg+vaw*vaw+2*vwg*vaw*cos((alpha*3.14)/180));
printf("WIND SPEED %.2lf\n",p);
printf("WIND DIRECTION %.2lf\n",q);
printf("DESIRED COURSE %.2lf\n",r);
printf("TRUE AIRSPEED %.2lf\n",s);
printf("AIRCRAFT HEADING %.2lf\n",phi);
printf("GROUND SPEED %.2lf\n\n",v);
}
}

 Learning poster
 Posts: 63
 Joined: Tue Mar 07, 2006 6:51 pm
 Location: india
i again try with this code by improving the value of pi
but still WA
but still WA
Code: Select all
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793115997963468544185161590576171875
main()
{
double vwg,thetaw,thetar,vaw,theta,alpha,phi,v,p,q,r,s;
while(scanf("%lf%lf%lf%lf",&vwg,&thetaw,&thetar,&vaw)!=EOF)
{
p=vwg,q=thetaw,r=thetar,s=vaw;
thetaw = thetaw  180.00;
if(thetaw<0)
thetaw=360.00+thetaw;
if(thetaw > thetar)
theta=thetawthetar;
else
theta=thetarthetaw;
if(theta > 180)
theta=360theta;
alpha=theta+(180/PI)*asin((vwg/vaw)*sin((PI*theta)/180));
if(thetaw > thetar)
{
if(thetawthetar > 180)
phi=thetaw+alpha180;
else
phi=thetawalpha;
if(phi<0)
phi=360+phi;
}
else
{
if(thetar  thetaw > 180)
phi=360+thetawalpha;
else
phi=alpha+ thetaw;
if(phi>360)
phi=phi  360;
}
v=sqrt(vwg*vwg+vaw*vaw+2*vwg*vaw*cos((alpha*PI)/180));
printf("WIND SPEED %.2lf\n",p);
printf("WIND DIRECTION %.2lf\n",q);
printf("DESIRED COURSE %.2lf\n",r);
printf("TRUE AIRSPEED %.2lf\n",s);
printf("AIRCRAFT HEADING %.2lf\n",phi);
printf("GROUND SPEED %.2lf\n\n",v);
}
}

 Learning poster
 Posts: 63
 Joined: Tue Mar 07, 2006 6:51 pm
 Location: india
hi everybody
i tried to solve this but keep getting WA i checked it for lot of inputs but i m not geeting the error .kindly give some input of accpted program...
here is my code plz check this....
i tried to solve this but keep getting WA i checked it for lot of inputs but i m not geeting the error .kindly give some input of accpted program...
here is my code plz check this....
Code: Select all
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793115997963468544185161590576171875
main()
{
double vwg,thetaw,thetar,vaw,theta,alpha,phi,v,p,q,r,s;
while(scanf("%lf%lf%lf%lf",&vwg,&thetaw,&thetar,&vaw)!=EOF)
{
p=vwg,q=thetaw,r=thetar,s=vaw;
thetaw = thetaw  180.00;
if(thetaw<0)
thetaw=360.00+thetaw;
if(thetaw > thetar)
theta=thetawthetar;
else
theta=thetarthetaw;
if(theta > 180)
theta=360theta;
alpha=theta+(180/PI)*asin((vwg/vaw)*sin((PI*theta)/180));
if(thetaw > thetar)
{
if(thetawthetar > 180)
phi=thetaw+alpha180;
else
phi=thetawalpha;
if(phi<0)
phi=360+phi;
}
else
{
if(thetar  thetaw > 180)
phi=360+thetawalpha;
else
phi=alpha+ thetaw;
if(phi>360)
phi=phi  360;
}
v=sqrt(vwg*vwg+vaw*vaw+2*vwg*vaw*cos((alpha*PI)/180));
printf("WIND SPEED %.2lf\n",p);
printf("WIND DIRECTION %.2lf\n",q);
printf("DESIRED COURSE %.2lf\n",r);
printf("TRUE AIRSPEED %.2lf\n",s);
printf("AIRCRAFT HEADING %.2lf\n",phi);
printf("GROUND SPEED %.2lf\n\n",v);
}
}