ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1030. Titanic

I got "Crash (ACCESS_VIOLATION)". What does it mean?
Posted by XiaoTian 18 Jan 2003 19:42
{No.1030 Titanic.}
Const
pi=3.1415926535897932384626433832795;
Var
Char1,NS1,EW1,NS2,EW2:Char;
A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer;
SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Real;
Var
Str1:String;
Code,Num:Integer;
Char1:Char;
Begin
Str1:='##';
If Char1 In ['0'..'9'] Then
Str1:=Str1+Char1;
Val(Str1,Num,Code);
End;
Procedure Cal(Theta1,Theta2:Real;NS,EW:Char;Var X,Y,Z:Real);
Begin
If NS='N' Then
Z:=Sin(Theta1)
Else Z:=-Sin(Theta1);
X:=Cos(Theta2)*Cos(Theta1);
If EW='E' Then
Y:=Sin(Theta2)*Cos(Theta1)
Else Y:=-Sin(Theta2)*Cos(Theta1);
End;
Begin

Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60)
+E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1);
Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60)
+E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2);

If (Abs(X1+X2)<1E-7) And (Abs(Y1+Y2)<1E-7) And (Abs(Z1+Z2)<1E-7)
Then
Alpha:=pi
Else Begin
SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2);
Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2;
End;
L:=Alpha*6875/2;
WriteLn('The distance to the iceberg: ',L:0:2,' miles.');
If 100-L>1E-7 Then
WriteLn('DANGER!');
End.
Re: I got "Crash (ACCESS_VIOLATION)". What does it mean?
Posted by Илья Гофман (Ilya Gofman) 18 Jan 2003 19:46
This possibly mean that you try to access the element of the array
with the number that doesn't exist or something like that.
Good Luck!!!
I correct it, but now WA. Why?
Posted by XiaoTian 19 Jan 2003 09:08
{No.1030 Titanic.}
{\$N+}
Const
pi=3.1415926535897932384626433832795;
Var
Char1,NS1,EW1,NS2,EW2:Char;
A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer;
SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Double;
Var
Str1:String;
Code,Num:Integer;
Char1:Char;
Begin
Str1:='';
If Char1 In ['0'..'9'] Then
Begin
Str1:=Str1+Char1;
If Char1 In ['0'..'9'] Then
Str1:=Str1+Char1;
End;
Val(Str1,Num,Code);
End;
Procedure Cal(Theta1,Theta2:Double;NS,EW:Char;Var X,Y,Z:Double);
Begin
If NS='N' Then
Z:=Sin(Theta1)
Else Z:=-Sin(Theta1);
X:=Cos(Theta2)*Cos(Theta1);
If EW='E' Then
Y:=Sin(Theta2)*Cos(Theta1)
Else Y:=-Sin(Theta2)*Cos(Theta1);
End;
Begin

Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60)
+E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1);
Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60)
+E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2);

If (Abs(X1+X2)<1E-10) And (Abs(Y1+Y2)<1E-10) And (Abs(Z1+Z2)<1E-
10) Then
Alpha:=pi
Else Begin
SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2);
Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2;
End;
L:=Alpha*6875/2;
WriteLn('The distance to the iceberg: ',L:0:2,' miles.');
If 100-L>0 Then
WriteLn('DANGER!');
End.
You see, in your program such case is possible: when you write distance 100.00, but write DANGER! Round error (-)
Posted by Dmitry 'Diman_YES' Kovalioff 19 Jan 2003 12:01
Error corrected, but I still got WA.
Posted by XiaoTian 19 Jan 2003 14:31
{No.1030 Titanic.}
{\$N+}
Const
pi=3.1415926535897932384626433832795;
Var
Char1,NS1,EW1,NS2,EW2:Char;
A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer;
SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Double;
Var
Str1:String;
Code,Num:Integer;
Char1:Char;
Begin
Str1:='';
If Char1 In ['0'..'9'] Then
Begin
Str1:=Str1+Char1;
If Char1 In ['0'..'9'] Then
Str1:=Str1+Char1;
End;
Val(Str1,Num,Code);
End;
Procedure Cal(Theta1,Theta2:Double;NS,EW:Char;Var X,Y,Z:Double);
Begin
If NS='N' Then
Z:=Sin(Theta1)
Else Z:=-Sin(Theta1);
X:=Cos(Theta2)*Cos(Theta1);
If EW='E' Then
Y:=Sin(Theta2)*Cos(Theta1)
Else Y:=-Sin(Theta2)*Cos(Theta1);
End;
Begin

Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60)
+E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1);
Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60)
+E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2);

If (Abs(X1+X2)<1E-10) And (Abs(Y1+Y2)<1E-10) And (Abs(Z1+Z2)<1E-
10) Then
Alpha:=pi
Else Begin
SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2);
Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2;
End;
L:=Alpha*6875/2;
Write('The distance to the iceberg: ');
Write(L:0:2);
WriteLn(' miles.');
If Round(L*100)<10000 Then
WriteLn('DANGER!');
End.
Maybe such case is possible: many messages in one test (-)
Posted by Dmitry 'Diman_YES' Kovalioff 19 Jan 2003 21:24
All the tests are here.I got them from Zhu Zheyuan.
Posted by Lin 21 Jan 2003 10:51
Message #488.
Current ship's coordinates are
45^00'00" SL
and 45^00'00" WL.
An iceberg was noticed at
45^00'00" NL
and 45^00'00" WL.
===
Message #488.
Current ship's coordinates are
41^46'00" NL
and 50^14'00" WL.
An iceberg was noticed at
41^14'11" NL
and 51^09'00" WL.
===
Message #488.
Current ship's coordinates are
45^00'00" SL
and 45^00'00" WL.
An iceberg was noticed at
45^00'00" NL
and 135^00'00" EL.
===
Message #488.
Current ship's coordinates are
90^00'00" NL
and 50^14'00" WL.
An iceberg was noticed at
90^00'00" SL
and 151^09'00" WL.
===
Message #488.
Current ship's coordinates are
0^00'00" NL
and 50^00'00" WL.
An iceberg was noticed at
0^00'00" SL
and 130^00'00" EL.
===
Message #488.
Current ship's coordinates are
40^00'00" NL
and 1^00'00" WL.
An iceberg was noticed at
40^00'00" NL
and 1^00'00" EL.
===
Message #488.
Current ship's coordinates are
40^09'18" NL
and 1^00'01" WL.
An iceberg was noticed at
40^50'11" NL
and 1^00'00" EL.
===
Message #488.
Current ship's coordinates are
40^09'19" NL
and 1^00'01" WL.
An iceberg was noticed at
40^50'12" NL
and 1^00'00" EL.
===
Posted by XiaoTian 22 Jan 2003 14:22
The distance to the iceberg: 5399.61 miles.
The distance to the iceberg: 52.04 miles.
DANGER!
The distance to the iceberg: 7199.48 miles.
The distance to the iceberg: 10799.22 miles.
The distance to the iceberg: 4799.66 miles.
The distance to the iceberg: 91.92 miles.
DANGER!
The distance to the iceberg: 100.00 miles.
The distance to the iceberg: 99.99 miles.
DANGER!
Posted by Sergei Pupyrev (USU) 10 Feb 2003 19:58
> The distance to the iceberg: 5399.61 miles.
> The distance to the iceberg: 52.04 miles.
> DANGER!
> The distance to the iceberg: 7199.48 miles.
> The distance to the iceberg: 10799.22 miles.
> The distance to the iceberg: 4799.66 miles.
> The distance to the iceberg: 91.92 miles.
> DANGER!
> The distance to the iceberg: 100.00 miles.
> The distance to the iceberg: 99.99 miles.
> DANGER!
>
Sorry
Posted by Sergei Pupyrev (USU) 10 Feb 2003 19:59
> The distance to the iceberg: 5399.61 miles.
> The distance to the iceberg: 52.04 miles.
> DANGER!
> The distance to the iceberg: 7199.48 miles.
> The distance to the iceberg: 10799.22 miles.
> The distance to the iceberg: 4799.66 miles.
> The distance to the iceberg: 91.92 miles.
> DANGER!
> The distance to the iceberg: 100.00 miles.
> The distance to the iceberg: 99.99 miles.
> DANGER!
>
Look carefully at test :
Message #488.
Current ship's coordinates are
45^00'00" SL
and 45^00'00" WL.
An iceberg was noticed at
45^00'00" NL
and 135^00'00" EL.
===
Re: Sorry
Posted by alp 21 Sep 2013 23:55
The distance to the iceberg: 5399.61 miles.
The distance to the iceberg: 52.04 miles.
DANGER!
The distance to the iceberg: 10799.22 miles.
The distance to the iceberg: 10799.22 miles.
The distance to the iceberg: 10799.22 miles.
The distance to the iceberg: 91.92 miles.
DANGER!
The distance to the iceberg: 100.00 miles.
The distance to the iceberg: 99.99 miles.
DANGER!