uva 11817 Tunnelling the Earth 球

题意:将地球看做半径为6371009米的球,现在知道两个点的纬度和经度,求一点从球表面到另一点和一点直线穿过球到达另一点的距离差。

题解:

先求出两点的三维坐标,然后用点积求得两点线段长。而球表面的路径就是这条线段所在圆弧,所以就可以通过角度求得球表面路径长。






代码:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;

const double pi=atan(1.0)*4;
const double r=6371009;

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 +(Vector3 A,Vector3 B){return Vector3(A.x+B.x,A.y+B.y,A.z+B.z);}
Vector3 operator -(Vector3 A,Vector3 B){return Vector3(A.x-B.x,A.y-B.y,A.z-B.z);}
Vector3 operator *(Vector3 A,double p){return Vector3(A.x*p,A.y*p,A.z*p);}
Vector3 operator /(Vector3 A,double p){return Vector3(A.x/p,A.y/p,A.z/p);}

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));}

Point3 get_point(double a,double b)
{
    Point3 p;
    p.x=r*cos(a)*cos(b);
    p.y=r*cos(a)*sin(b);
    p.z=r*sin(a);
    return p;
}

double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{

}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int i,j,k;
        double x1,y1,z1,x2,y2,z2,e[4];
        for(i=0;i<4;i++)
        {
            //输入纬度和经度
            scanf("%lf",&e[i]);
            e[i]=e[i]/180.0*pi;
        }
        Point3 a,b;
        double ans1,ans2;
        a=get_point(e[0],e[1]);
        b=get_point(e[2],e[3]);
        ans1=Length(a-b);
        ans2=asin(ans1/(2.0*r))*2*r;
        printf("%d\n",(int)(ans2-ans1+0.5));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值