ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1030. Titanic

I need help!! anyone
Posted by Egor 13 Jun 2019 14:27
Hello! I`ve got a code, equations must be right, but the result is different from sample. I don`t know what the problem is. Please, help!! My result is 45,28, whereas the sample`s one is 52,04.

static void Main(string[] args)
{
const double D = 6875;
const double pi = 3.1415926535897932384626433;
string trash;
char[] separators = new[] { ' ', '^', '"', '\''};
/* double shipx, shipy, shipz, icex, icey, icez; */
for (int i = 0; i < 3; i++)
trash = Console.ReadLine();
var shipLat = Console.ReadLine().Split(separators);
var shipLong = Console.ReadLine().Split(separators);
trash = Console.ReadLine();
var iceLat = Console.ReadLine().Split(separators);
var iceLong = Console.ReadLine().Split(separators);
trash = Console.ReadLine();

double phi1 = (int.Parse(shipLat) + (int.Parse(shipLat) + int.Parse(shipLat) / 60) / 60) * (pi / 180);
double phi2 = (int.Parse(shipLong) + (int.Parse(shipLong) + int.Parse(shipLong) / 60) / 60) * (pi / 180);
if (shipLat == "SL") phi1 = -phi1;
if (shipLong == "WL") phi2 = -phi2;

double L1 = (int.Parse(iceLat) + (int.Parse(iceLat) + int.Parse(iceLat) / 60)/60) * (pi / 180);
double L2 = (int.Parse(iceLong) + (int.Parse(iceLong) + int.Parse(iceLong) / 60)/60) * (pi / 180);
if (iceLat == "SL") L1 = -L1;
if (iceLong == "WL") L2 = -L2;

double ans = Math.Acos(Math.Sin(phi1) * Math.Sin(L1) + Math.Cos(phi1) * Math.Cos(L1) * Math.Cos(L2-phi2));
double dist = ans * D/2;

Console.Write("The distance to the iceberg: ");
Console.WriteLine("{0:0.00}", dist);
if (100.00 - dist > 0.005) Console.WriteLine("DANGER!");
}
Re: I need help!! anyone
Posted by Egor 14 Jun 2019 22:54
The problem is solved. It`s impossible to have the right answer with INT parsing. You need to use double.