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've got WA 1. Please Help.
Posted by MadMag 10 Sep 2010 23:15
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;

#define PI 3.1415926535897932384626433

int lat1, lat2, lat3, lon1, lon2, lon3, trash;
char latc, lonc;

long double latf, lats, lonf, lons;
long double sq(double x){
  return x*x;
}

int main(void){
  scanf("Message #%d.\nReceived at %d:%d:%d.\nCurrent ship’s coordinates are\n%d^%d'%d\" %cL\nand %d^%d'%d\" %cL.\n",
         &trash, &trash, &trash, &trash, &lat1, &lat2, &lat3, &latc, &lon1, &lon2, &lon3, &lonc);
  lats = (latc=='N'?1:-1)*(lat1 + (lat2 + lat3/60.0)/60.0)*PI/180.0;
  lons = (lonc=='W'?-1:1)*(lon1 + (lon2 + lon3/60.0)/60.0)*PI/180.0;


  scanf("An iceberg was noticed at\n%d^%d'%d\" %cL\nand %d^%d'%d\" %cL.",
         &lat1, &lat2, &lat3, &latc, &lon1, &lon2, &lon3, &lonc);
  latf = (latc=='N'?1:-1)*(lat1 + (lat2 + lat3/60.0)/60.0)*PI/180.0;
  lonf = (lonc=='W'?-1:1)*(lon1 + (lon2 + lon3/60.0)/60.0)*PI/180.0;

  double dlon = lonf - lons, dlat = latf - lats;

  double a = acos(sin(lats)*sin(latf) + cos(lats)*cos(latf)*cos(dlon));
  double len =  3437.5*a;
  printf("The distance to the iceberg: %.2lf miles.\n", len);
  if(100.00-len>0.005)
    printf("DANGER!\n");
  return 0;
}

Am I wright about input?
Re: I've got WA 1. Please Help.
Posted by tiancaihb 11 Sep 2010 08:54
Have you debugged locally? Change the word "ship’s" to "ship's" and you'll get AC.
Anyway, your algorithm is amazing. For example, you even don't use epsilon in "if(100.00-len>0.005)"... Very impressive.