HDU 3756

很容易就想到把三维转化成了二维,求出点离Z轴的距离,把这个距离当成X坐标,Z轴当Y坐标,然后就变成了求一个直角三角形覆盖这些点

像上一题一样,确定斜率直线的时候,必定是有一点在线上的。于是,可以把直线看成垂直X轴,按角度旋转点即可。

也有二分高度的做法。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

struct Point{
	double x,y;
};
Point point[10050];
int n;
const double PI=3.141592653;
const double inf=1e10;
double ansx,ansh;
double cal(double ang){
	double cs=cos(ang),sn=sin(ang);
	double x;
	double xmax=-inf;
	for(int i=1;i<=n;i++){
		x=cs*point[i].x-sn*point[i].y;
		xmax=max(xmax,x);
	}
	ang=-ang;
	cs=cos(ang),sn=sin(ang);
	ansx=xmax/cs;
	ansh=xmax/sn;
	return ansx*ansx*PI*ansh/3;
}

int main(){
	int T;double x,y,z;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%lf%lf%lf",&x,&y,&z);
			point[i].y=z;
			point[i].x=sqrt(x*x+y*y);
		}
		double l=-90*PI/180,r=0; double m,mm;
		while(l+(1e-8)<r){
			m=l+(r-l)/3;
			mm=r-(r-l)/3;
			if(cal(m)>cal(mm))
			l=m;
			else r=mm;
		}
		cal(l);
		printf("%.3lf %.3lf\n",ansh,ansx);
	}
	return 0;
}

  

转载于:https://www.cnblogs.com/jie-dcai/p/4275962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值