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

solution by gladoff
Posted by DavidРЕМШgladoff#c++ 30 Nov 2014 11:35
#include <iostream>
  #include <math.h>
  using namespace std;
  const long double D=6875;
  const long double pi=3.1415926535897932384626433;
  struct postype{
      long double x,y,z;
      };
  int x1,x2,x3,yy1,y2,y3;
 int sx1,sx2,sx3,syy1,sy2,sy3;
 char str[100000];
 char xstr[10],ystr[10],sxstr[10],systr[10];
 postype ship,ice;
 long double angle1,angle2;

 long double dis(double a,double b,double c,double d,double e,double f){
     a-=d;
     b-=e;
     c-=f;
     return sqrt(a*a+b*b+c*c);
     }

 int main(){
     for (int i=1;i<=3;++i) gets(str);
     scanf("%d^%d'%d\" %s\n",&x1,&x2,&x3,&xstr);
     scanf("and %d^%d'%d\" %s\n",&yy1,&y2,&y3,&ystr);
     gets(str);
     scanf("%d^%d'%d\" %s\n",&sx1,&sx2,&sx3,&sxstr);
     scanf("and %d^%d'%d\" %s\n",&syy1,&sy2,&sy3,&systr);
     gets(str);

     double a=x1,b=x2,c=x3;
     angle1=a*3600+b*60.0+c;
     angle1/=3600.0*180;
     angle1*=pi;
     if (xstr[0]=='S') angle1=-angle1;
     a=yy1;b=y2;c=y3;
     angle2=a*3600+b*60.0+c;
     angle2/=3600.0*180;
     angle2*=pi;
     if (ystr[0]=='W') angle2=-angle2;
     ship.x=D/2*cos(angle1)*cos(angle2);
     ship.y=D/2*cos(angle1)*sin(angle2);
     ship.z=D/2*sin(angle1);

     a=sx1,b=sx2,c=sx3;
     angle1=a*3600+b*60+c;
     angle1/=3600.0*180;
     angle1*=pi;
     if (sxstr[0]=='S') angle1=-angle1;
     a=syy1;b=sy2;c=sy3;
     angle2=a*3600+b*60+c;
     angle2/=3600.0*180;
     angle2*=pi;
     if (systr[0]=='W') angle2=-angle2;
     ice.x=D/2*cos(angle1)*cos(angle2);
     ice.y=D/2*cos(angle1)*sin(angle2);
     ice.z=D/2*sin(angle1);

     long double linedis=dis(ship.x,ship.y,ship.z,ice.x,ice.y,ice.z);
     linedis/=2;
     long double AA=asin(linedis*2/D)*2;
     long double ans=AA;
     ans=ans*D/2;

     printf("The distance to the iceberg: ");
     cout.precision(2);
     cout<<fixed;
     cout<<ans;
     printf(" miles.\n");
     if (100.00-ans>0.005) printf("DANGER!");
     }