URAL 1075. Thread in a Space

又被题给虐了。三维的,不过可以转化为二维来看。

两个点之间有一个球(两点在球外),两个点之间扯一条线,问线的最短距离。

两种情况

1、AB不会碰着球,直接求AB之间距离即可

2、会碰着球。

第二种情况比较纠结,有同学用物理方法说明,那一段弧一定过球的大圆。。。过大圆的话,情况就是下图了,就求得红色线以及在圆上的那段弧了。这个简单,求得红色的角度就能求出来弧长了。


#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)

using namespace std;

const double eps = 1e-6;
struct point3 {
	double x, y, z;
	void get()
	{
		scanf("%lf%lf%lf", &x, &y, &z);
	}
	point3(){};
	point3(double x, double y, double z) : x(x), y(y), z(z) {}
};

double disp2p(point3 a, point3 b)
{
	return sqrt( (a.x - b.x)*(a.x - b.x) +
				 (a.y - b.y)*(a.y - b.y) +
				 (a.z - b.z)*(a.z - b.z) );
}
point3 a, b, c;
double r;
double area_triangle(double a,double b,double c)
{
	double p = (a+b+c)/2.0;
	return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
	a.get(); b.get(); c.get();
	scanf("%lf", &r);
	double ans = 0;
	double ac = disp2p(a, c);
	double bc = disp2p(b, c);
	double ab = disp2p(a, b);

	ans += sqrt( ac*ac - r*r );
	ans += sqrt( bc*bc - r*r );
	
	double angc = acos((ac*ac + bc*bc - ab*ab)/(2*ac*bc));
	double anga = acos(r/ac);
	double angb = acos(r/bc);
	double ang = angc - anga - angb;
	ans += ang * r;
	
	if( anga + angb >= angc - eps )
		printf("%.2lf\n", ab);
	else
		printf("%.2lf\n", ans);

return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值