UVa 11817 Tunnelling the Earth 计算球面距离

题目地址:pdf版

就是高数里面学的球坐标。用到一些三维几何的模板。

话说手写“最近的整数”wa了,直接%.0lf还过了。真实奇怪啊

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const double eps=1e-10;
const double PI=acos(-1);
int dcmp(double x)
{
    return (x>eps)-(x<-eps);
}

struct Point3
{
    double x,y,z;
    Point3(double x=0,double y=0,double z=0):x(x),y(y),z(z) {}
    
};

typedef Point3 Vector3;

Vector3 operator+(Point3 A,Point3 B)
{
    return Point3(A.x+B.x,A.y+B.y,A.z+B.z);
    
}

Vector3 operator-(Point3 A,Point3 B)
{
    return Point3(A.x-B.x,A.y-B.y,A.z-B.z);
    
}

Vector3 operator*(Point3 A,double p)
{
    return Point3(A.x*p,A.y*p,A.z*p);
    
}

Vector3 operator/(Point3 A,double p)
{
    return Point3(A.x/p,A.y/p,A.z/p);
    
}

bool operator<(Point3 &A,Point3 &B)
{
    return A.x<B.x||(A.x==B.x&&A.y<B.y)||(A.x==B.x&&A.y==B.y&&A.z<B.z);
    
}
bool operator==(Point3 &A,Point3 &B)
{
    return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0&&dcmp(A.z-B.z)==0;
}
ostream & operator<<(ostream & out,Vector3 A)
{
    out<<A.x<<' '<<A.y<<' '<<A.z<<endl;
    
    return out;
}


double Dot(Vector3 A,Vector3 B)
{
    return  A.x*B.x+A.y*B.y+A.z*B.z;
}

double Length(Vector3 A)
{
    return sqrt(Dot(A,A));
}

double Angle(Vector3 A,Vector3 B)
{
    return acos(Dot(A,B)/Length(A)/Length(B));
}


Vector3 Cross(Vector3 A,Vector3 B)
{
    return  Vector3(A.y*B.z-A.z*B.y,A.x*B.z-A.z*B.x,A.x*B.y-A.y*B.x);
}

double Area2(Point3 A,Point3 B,Point3 C)
{
    return Length(Cross(B-A,C-A));
}


int nearest(double p)
{
    int a=floor(p);
    int b=ceil(p);
    
    if(b-p>=p-a) return b;
    else return a;
}
int main()
{
    
    int T;
    cin>>T;
    double a1,b1,a2,b2;
    double R=6371009;
    double x1,y1,z1,x2,y2,z2;
    
    while(T--)
    {
        cin>>b1>>a1>>b2>>a2;
        
        b1=b1/180.0*PI;
        a1=a1/180.0*PI;
        b2=b2/180.0*PI;
        a2=a2/180.0*PI;
        
        
        x1=R*cos(b1)*cos(a1);
        y1=R*cos(b1)*sin(a1);
        z1=R*sin(b1);
        
        x2=R*cos(b2)*cos(a2);
        y2=R*cos(b2)*sin(a2);
        z2=R*sin(b2);
        
        
       // printf("%lf %lf %lf %lf %lf %lf\n",x1,y1,z1,x2,y2,z2);
        Point3 A=Point3(x1,y1,z1);
        Point3 B=Point3(x2,y2,z2);
        
        double real_dist=Length(A-B);
        
        Point3 P;
        double arc_dist=Angle(A-P, B-P)*R;
        
        printf("%.0lf\n",arc_dist-real_dist);
        
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值