LJOJ 1576 Easy Problem

题意就是http://blog.csdn.net/kaisa158/article/details/47023997

刚开始把判两个点几乎重合的那个-写了sigma{sqr(每个点)}被卡精度,改成abs就a了

//By Richard
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#define rep(x,y,z) for (int x=(y);(x)<=(z);(x)++)
#define per(x,y,z) for (int x=(y);(x)>=(z);(x)--)
#define log2(x) (31-__builtin_clz(x))
#define mod (int)(1e9+7)
#define inf 0x3f3f3f3f
#define cls(x) memset(x,0,sizeof(x))
#ifdef DEBUG
#define debugdo(X) X
#define debugndo(X)
#define debugout(X) cout<<(#X)<<"="<<(X)<<endl
#else
#define debugdo(X)
#define debugndo(X) X
#define debugout(X)
#endif // debug
#ifdef ONLINE_JUDGE
#define debugdo(X)
#define debugndo(X)
#define debugout(X)
#endif
#define putarray(x,n) rep(iiii,1,n) printf("%d ",x[iiii])
#define mp make_pair
using namespace std;
typedef pair<int,int> pairs;
typedef long long LL;
/read3.0
template <typename T>
inline void read(T &x){char ch;x=0;bool flag=false;ch=getchar();while (ch>'9'||ch<'0') {ch=getchar();if (ch=='-') flag=true;}while ((ch<='9'&&ch>='0')){x=x*10+ch-'0';ch=getchar();}if (flag) x*=-1;}
template <typename T>
inline void read(T &x,T &y){read(x);read(y);}
/variables&functions
typedef long double LD;
int T;
#define sqr(x) ((x)*(x))
struct point
{
	LD x,y,z;
	point(LD a=0,LD b=0,LD c=0):x(a),y(b),z(c){}
	inline bool operator<(point b)const{return x==b.x?y<b.y:x<b.x;}
	inline LD operator-(point b)const{return abs(x-b.x)+abs(y-b.y)+abs(z-b.z);}
};
double xp,yp,zp,x,y,z,xx,yy,zz;
const LD eps=0.000000000001;
LD dis(const point &x,const point &y)
{
	return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y)+sqr(x.z-y.z));
}
int main()
{
	read(T);
	rep(iii,1,T)
	{
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&xp,&yp,&zp,&x,&y,&z,&xx,&yy,&zz);
		point pp(xp,yp,zp);
		point l(x,y,z),r(xx,yy,zz);
		if (r<l) swap(l,r);
		while (r-l>eps)
		{
			point ll((r.x-l.x)/3+l.x,(r.y-l.y)/3+l.y,(r.z-l.z)/3+l.z),rr((r.x-l.x)*2/3+l.x,(r.y-l.y)*2/3+l.y,(r.z-l.z)*2/3+l.z);
			LD disll=dis(pp,ll),disrr=dis(pp,rr);
			if (disll<disrr) r=rr;
			else l=ll;
		}
		printf("Case %d: %.2lf\n",iii,(double)dis(pp,l));
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值