LA4986 Dome of Circus

微微发亮的传送门

最开始比较傻,一直认为是乱搞,结果乱搞了一大通,最后输出的结果我自己的不认识

后来有了个比较神的思想,那就是三分搜索,首先,我们可以知道,圆锥的体积是(r*r*h*pi)/3,那么这里面的不定量就是r和h,也就是说我们需要求得就是r*r*h的最小值,而r和h又是相关的,也就是说我们知道了一个量就可以通过圆锥轴截面的那个三角形得知另一个量,同时这个函数是一个凸性函数,已经满足了三分的性质,所以我们可以用三分搜索来解决。于是乎我三分h,利用h求出来r,然后一点点地逼近最小值,这样的话这道题就可以被愉快的干掉了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
const int maxn = (int)1e4 + 10;
const double eps = 1e-8;
int dblcmp(double x){
	if (fabs(x)) return 0;
	return x > 0 ? 1 : -1;
}
const double pi = acos(-1.0);
inline double sqr(double x){
	return x * x;
}
struct point{
	double x, y;
};
int n;
point p[maxn];
double check(double h){  
    double R = 0;  
    for(int i = 0; i < n; i++)
    	if(R * (h - p[i].y) < h * p[i].x)
    		R = h * p[i].x / (h - p[i].y);
    return R;  
}
void solve(){
	double a, b, c, l, r;
	l = 0;
	for (int i = 0; i < n; i++){
		scanf("%lf%lf%lf", &a, &b, &c);
		p[i].x = sqrt(sqr(a) + sqr(b));
		p[i].y = c;
		l = max(l, c);
	}
	r = 1 << 30;
	while(r - l > eps){
		double tmp = (r - l) / 3.0;
		double mid1 = l + tmp, mid2 = l + tmp + tmp;
		double r1 = check(mid1), r2 = check(mid2);
		if (sqr(r1) * mid1 > sqr(r2) * mid2)
			l = mid1;
		else r = mid2;
	}
	printf("%.3lf %.3lf\n", l + eps, check(l) + eps);
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in", "rt", stdin);
	#endif
	while(scanf("%d", &n) == 1) solve();
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值