您的位置:首页 > 其它

G - Dome of Circus UVALive - 4986 (三分)

2017-08-06 18:28 459 查看
https://vjudge.net/contest/123097#problem/G

三分最后一题

其实看上去像一个三维问题,分分钟化成二维平面内的问题, 三分的是体积,我们只要比较r*r*h的大小就行,

下凸函数,自己画一下图感受一下就行了. 还是用斜率的角度走一下流程.

#include<cstdio>
#include<iostream>
#include<cmath>

const int maxn = 1e4+5;
const double eps = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int n;
double ansr, ansh;
struct Point{
double x,y;
Point(){}
Point(double x, double y):x(x),y(y){}
}p[maxn];

double cal(double ang){
double maxv = 0;
double a,b;
for(int i = 0; i < n; i++){
b = p[i].x*tan(ang) + p[i].y;
a = b/tan(ang);
maxv = max(maxv, a*a*b);
}
return maxv;
}

int main(){
double xx,yy,zz;
while(~scanf("%d",&n) && n){
for(int i = 0; i < n; i++){
scanf("%lf%lf%lf",&xx,&yy,&zz);
p[i].x = eps+sqrt(xx*xx+yy*yy);
p[i].y = zz;
}
double l = 0, r = PI/2, mid1, mid2;
for(int i = 0; i < 100; i++){
mid1 = l + (r - l)/3;
mid2 = r - (r - l)/3;
if(cal(mid1) < cal(mid2)) r = mid2;
else l = mid1;
}
double v = cal(l);
ansr = pow(v/tan(l),(double)(1.0/3));
ansh = tan(l)*ansr;
printf("%.3lf %.3lf\n",ansh,ansr);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  三维 三分 计算几何