ENG  RUSTimus 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[0]) + (int.Parse(shipLat[1]) + int.Parse(shipLat[2]) / 60) / 60) * (pi / 180);
            double phi2 = (int.Parse(shipLong[1]) + (int.Parse(shipLong[2]) + int.Parse(shipLong[3]) / 60) / 60) * (pi / 180);
            if (shipLat[3] == "SL") phi1 = -phi1;
            if (shipLong[4] == "WL") phi2 = -phi2;

            double L1 = (int.Parse(iceLat[0]) + (int.Parse(iceLat[1]) + int.Parse(iceLat[2]) / 60)/60) * (pi / 180);
            double L2 = (int.Parse(iceLong[1]) + (int.Parse(iceLong[2]) + int.Parse(iceLong[3]) / 60)/60) * (pi / 180);
            if (iceLat[3] == "SL") L1 = -L1;
            if (iceLong[4] == "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.