HOJ 2016 Conic Distance

http://acm.hit.edu.cn/hoj/problem/view?id=2016

給出兩個點的 計算這兩點在圓錐面上的最短距離

把圓錐展開爲扇形 兩點間距離利用餘弦定理計算

注意角度

#include <stdio.h>
#include <math.h>

double min(double a, double b);

int main()
{
    const double pi=acos(-1);
    double r, h, d1, a1, d2, a2;
    double R, length;//母線和弧長
    double theta0, theta, angle;//3D夾角、平面扇形夾角、兩給定點與扇形頂點連線夾角
    double distance;

    while (scanf("%lf %lf %lf %lf %lf %lf", &r, &h, &d1, &a1, &d2, &a2) != EOF)
    {
        R = sqrt(r * r+h * h);
        length = 2 * pi * r;
        theta = length / R;
        theta0 = fabs(a1-a2);
        angle = theta0 * theta / 360.0;
        angle = min(angle , theta-angle);
        distance = sqrt(d1 * d1 + d2 * d2 - 2 * d1 * d2 * cos(angle) );//餘弦定理
        printf("%.2lf\n", distance);
    }

    return 0;
}

double min(double a, double b)
{
    if(a > b)
        return b;
    return a;
}


 

發佈了80 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章