⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pku 3407 球体表面距离.txt

📁 POJ上一些计算几何题的代码………………
💻 TXT
字号:
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

//PKU 3407 球体表面距离
//#define NMAX 
//#define INFI 
#define PI 3.1415926
#define MH make_heap
#define OH pop_heap
#define PH push_heap
#define PB push_back
#define OB pop_back

double x[2],y[2],z[2];
double R=6370;
char shuru_ewg[2],shuru_nsg[2];
double shuru_ew1[2],shuru_ew2[2],shuru_ns1[2],shuru_ns2[2],shuru_ew[2],shuru_ns[2];

void cal(int k,char ewg,char nsg,double ew,double ns)
{
    double temp;
 //   printf("ew=%.3f ns=%.3f\n",ew,ns);
  if(nsg=='N') z[k]=sin(ns)*R;
  else z[k]=-sin(ns)*R;
  temp=sqrt(R*R-z[k]*z[k]);
  if(ewg=='E') 
  {
      x[k]=cos(ew)*temp;
      y[k]=sin(ew)*temp;
  }
  else
  {
      x[k]=cos(ew)*temp;
      y[k]=-sin(ew)*temp;
  }
}

double getdis(double x1,double x2,double y1,double y2,double z1,double z2)
{
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
}

void solve()
{
    int i;
    double dis,q1,q2;
    for(i=0;i<2;i++)
    {
        cal(i,shuru_ewg[i],shuru_nsg[i],shuru_ew[i],shuru_ns[i]);
  //      printf("%.3f  %.3f  %.3f\n",x[i],y[i],z[i]);
    }
    dis=getdis(x[0],x[1],y[0],y[1],z[0],z[1]);
 //   printf("dos=%.3f\n",sqrt(dis));
    q1=(2*R*R-dis)/(2*R*R);
    q2=acos(q1)*R;
    printf("%.3f\n",q2);
}
int main()
{
    char s1[4],s2[4];
  //  printf("%.3lf\n",sin(PI));
    scanf("%lf %lf %s %lf %lf %s",&shuru_ns1[0],&shuru_ns2[0],s1,&shuru_ew1[0],&shuru_ew2[0],s2);
    shuru_nsg[0]=s1[0];
    shuru_ewg[0]=s2[0];
    shuru_ns[0]=(shuru_ns1[0]+shuru_ns2[0]/60.0)*PI/180.0;
    shuru_ew[0]=(shuru_ew1[0]+shuru_ew2[0]/60.0)*PI/180.0;
     scanf("%lf %lf %s %lf %lf %s",&shuru_ns1[1],&shuru_ns2[1],s1,&shuru_ew1[1],&shuru_ew2[1],s2);
    shuru_nsg[1]=s1[0];
    shuru_ewg[1]=s2[0];
    shuru_ns[1]=(shuru_ns1[1]+shuru_ns2[1]/60.0)*PI/180.0;
    shuru_ew[1]=(shuru_ew1[1]+shuru_ew2[1]/60.0)*PI/180.0;
    solve();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -