您的位置:首页 > 其它

hdu 3756 三分 Dome of Circus

2012-09-15 10:59 337 查看
题意:

给你很多个点,让你输出一个r和h,使这样的圆锥体能覆盖给出的所有点并且体积最小。

题解:

三分(因为是个最值的问题)。枚举r,得到h。

做题过程:

wa了一两次。刚开始是因为只输出2位小数,而题目的要求是输出3位小数。后来就再也找不到错误了。 最后,在今天,将三分的上限改了一改,就A了。。。只能说,我还too young ,too simple啊。。。

/*
Pro: 0

Sol:

date:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#define eps 1e-7
#include <set>
#include <vector>
using namespace std;
struct point{
double x,y,z;
point(){}
point(double a, double b, double c){x = a, y = b, z = c;}
}p[11111];
int n,T;
double a,b,c;
double cal(double r){
double h ,Max = 0;
for(int i = 0; i < n; i ++){
h = p[i].z * r / (r - sqrt(p[i].x * p[i].x + p[i].y * p[i].y));
Max = max(h,Max);
}
return r * r * Max;
}
void thi(double &r, double &h){
double low = 0.0, high = 10000;
double m1,m2;
while(low + eps < high){
m1 = (low + high) / 2.0;
m2 = (m1 + high) / 2.0;
if(cal(m1) <= cal(m2)) high = m2;
else {
low = m1;
}
}
r = low;
h = -1;
for(int i = 0; i < n; i ++){
h = max(h,p[i].z * r / (r - sqrt(p[i].x * p[i].x + p[i].y * p[i].y)) );
}
}
int main(){
scanf("%d",&T);
while(T --){
scanf("%d",&n);
for(int i = 0; i < n; i ++){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
double r,h;
thi(r,h);
printf("%.3f %.3f\n",h,r);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: