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

Why do I awlays get WA? Can somebody help?
Posted by Kolio 5 Jan 2003 15:43
This is my source code:

#include <stdio.h>
#include <math.h>
#include <string.h>

double w1,l1;
double w2,l2;

double x1,x2,x3;
double Y1,Y2,Y3;

const double r = 3437.5;
const double pi = 3.14159265358979323846;

int scan(void)
{
    int num, hh, mm, ss;
    double x1,x2,x3;
    char str[5];

    if(scanf("Message #%d.\n", &num) <= 0)
        return 0;
    scanf("Received at %d:%d:%d.\n", &hh, &mm, &ss);
    scanf("Current ship&#8217;s coordinates are\n");

    scanf("%lf^%lf'%lf\" %s\n", &x1, &x2, &x3, str);
    if( str[0] == 'S' )
    {
        x1=-x1;
        x2=-x2;
        x3=-x3;
    }

    w1 = (x1+x2/60+x3/3600)/180*pi;

    scanf("and %lf^%lf'%lf\" %s\n", &x1, &x2, &x3, str);
    if( str[0] == 'E' )
    {
        x1=-x1;
        x2=-x2;
        x3=-x3;
    }

    l1 = (x1+x2/60+x3/3600)/180*pi;

    scanf("An iceberg was noticed at\n");

    scanf("%lf^%lf'%lf\" %s\n", &x1, &x2, &x3, str);
    if( str[0] == 'S')
    {
        x1=-x1;
        x2=-x2;
        x3=-x3;
    }

    w2 = (x1+x2/60+x3/3600)/180*pi;

    scanf("and %lf^%lf'%lf\" %s\n", &x1, &x2, &x3, str);
    if( str[0] == 'E')
    {
        x1=-x1;
        x2=-x2;
        x3=-x3;
    }

    l2 = (x1+x2/60+x3/3600)/180*pi;

    scanf("===\n");
    return 1;
}

void coord(double w, double l, double& a1, double& a2, double& a3)
{
    a1 = cos(w)*cos(l);
    a2 = cos(w)*sin(l);
    a3 = sin(w);
}

double dist2(double a1, double a2, double a3, double b1, double b2,
double b3)
{
    return (a1-b1)*(a1-b1)+(a2-b2)*(a2-b2)+(a3-b3)*(a3-b3);
}

double doit(void)
{
    coord(w1,l1, x1, x2, x3);
    coord(w2,l2, Y1, Y2, Y3);


    double res = r * acos (x1*Y1 + x2*Y2 + x3*Y3);
    return res;
/*
      double x = dist2(x1,x2,x3,Y1,Y2,Y3);
    double cosfi = 1-x/2;
    double fi = acos(cosfi);

     return fi*r;
*/

}

int main(void)
{
#ifndef ONLINE_JUDGE
    freopen("1030.in", "r", stdin);
#endif


    while(scan())
    {
        double res = doit();

        if ((unsigned)printf("The distance to the iceberg: %
0.2lf miles.\n",res) <
            strlen("The distance to the iceberg: 100.00
miles.\n") )
            printf("DANGER!\n");
/*
        printf("The distance to the iceberg: %.2lf miles.\n",
res);
        if(res<99.995)
            printf("DANGER!\n");
*/
    }

#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif
    return 0;
}