10517 - Wind of Change!

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

Moderator: Board moderators

Post Reply
lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

10517 - Wind of Change!

Post by lowai »

i use the following formula to calculate the latitude

Code: Select all

        m cos(n/R) - n
tan a = --------------
          m sin(n/R)
can anyone tell me what are the situations that i should output 'invalid or impossible'?
mbakht
New poster
Posts: 16
Joined: Fri Feb 28, 2003 7:54 pm
Location: Bangladesh
Contact:

Post by mbakht »

If any of the two conditions is false:

1. n < 1001

2. a >= 0 && a <= 70
lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

Post by lowai »

i still got WA.
[pascal]
const R = 6378.0;
var
i, kase : integer;
n, m : double;
a, t1, t2 : double;
begin
readln(kase);
for i := 1 to kase do
begin
readln(n, m);
write('Case ', i, ': ');
if (n >= 1001) or (n >= m) then
begin
writeln('Invalid or impossible.');
continue;
end;
t1 := m * cos(n / R);
if t1 < n then
begin
writeln('Invalid or impossible.');
continue;
end;
if abs(n) < 1e-7 then
begin
writeln('Invalid or impossible.');
continue;
end;
t2 := m * sin(n / R);
t1 := (t1 - n) / t2;
a := arctan(t1);
a := a * 180 / pi;

if a > 70 then
begin
writeln('Invalid or impossible.');
continue;
end;

write(trunc(a), ' deg ');
a := frac(a);
a := a * 60;
write(trunc(a), ' min ');
a := frac(a);
a := a * 60;
writeln(round(a), ' sec');
end;
end.
[/pascal]
Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm

Post by Faizur »

I also get wa with the same formula.
pls give some typical i/o .........
Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

It may also happened i u dont take all the variables in double
my 1st code with long (deg, min) proved WA :wink:
Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm

again wa

Post by Faizur »

I use double ..But again WA

Code: Select all

Sorrry, Code has been removed :lol: 
Last edited by Faizur on Wed Jul 02, 2003 8:19 pm, edited 1 time in total.
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

at first thanks to mehedi bakht bhai...
mbakht wrote:If any of the two conditions is false:
1. n < 1001
2. a >= 0 && a <= 70
i was missing the first one. :-?

to Faizur...
your first invalid condition checking is not right

Code: Select all

         if(n>1009.9) 
         { 
      printf("Invalid or impossible.\n"); 
      continue; 
         } 
rather it should be

Code: Select all

         if(n>=1001.0) 
         { 
      printf("Invalid or impossible.\n"); 
      i++;
      continue; 
         } 
and you also missed the i++ stuff here.
try to use degree minute second in int rather than double to avoid precision errors...

Code: Select all

          else 
          { 
        angle*=(180/pi); 
        int dg = (int)angle;
        min=angle-(long)angle; 
        min*=60;
        int mn = (int)min;
        sec=min-(long)min; 
        sec*=60; 
        int sc = (int)(sec+0.5);     // sec should be rounded
        printf("%d deg %d min %d sec\n",dg,mn,sc); 
          } 
Greetings...
Istiaque Ahmed [the LA-Z-BOy]
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

10517

Post by htl »

I think it's the precision prob. But I'm so confused that how do I get the integer part of a floating-point number. Can someone help me??
[c]
#include<stdio.h>
#include<math.h>
void main(void)
{
int count,x;
double n,m,pi,theta,a,b,angle;
pi=2*acos(0);
scanf("%d",&count);
for(x=1;x<=count;x++)
{
scanf("%lf %lf",&n,&m);
printf("Case %d: ",x);
theta=n/6378,a=m*cos(theta)-n,b=m*sin(theta);
if(n>=1001 || a<0 || (angle=atan(a/b)*180/pi)<0 || angle>70)
printf("Invalid or impossible.\n");
else
{
printf("%ld deg ",(long)angle);
angle=angle-(long)angle,angle*=60;
printf("%ld min ",(long)angle);
angle=angle-(long)angle,angle*=60;
printf("%.0lf sec\n",(long)angle);
}
}
}
[/c]
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

try calculating the second part of the lat. in integer...
[cpp] else
{
printf("%ld deg ",(long)angle);
angle=angle-(long)angle,angle*=60;
printf("%ld min ",(long)angle);
angle=angle-(long)angle,angle*=60;
int sec = (int)(angle+0.5); // second in int + rounding
printf("%d sec\n",sec);
} [/cpp]
Greetings...
Istiaque Ahmed [the LA-Z-BOy]
Faizur
New poster
Posts: 39
Joined: Fri Jun 06, 2003 3:04 pm

Post by Faizur »

Thanks a lot to the LA-Z-BOy .I get AC at last.
greetings...
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

to lowai...
use
[pascal] write(trunc(a), ' deg ');
a := frac(a);
a := a * 60;
write(trunc(a), ' min ');
a := frac(a);
a := a * 60;
a := a+0.5;
writeln(trunc(a), ' sec'); [/pascal]
for output of `second' instead.
thanks.
Istiaque Ahmed [the LA-Z-BOy]
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl »

It really works!!

Thanks very much for teaching another method of rounding! :D
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post by w k »

Could You post some I/O?

Wojciech
Post Reply

Return to “Volume 105 (10500-10599)”