UVa 1473 - Dome of Circus 三分
2013-07-20 17:37
197 查看
把所有的点都映射到XOZ这个平面的第一象限内,则这个三维问题可以转化二维问题:
求一条直线,使所有点在这条直线的下方,直线与X轴和Z轴围成的三角形旋转形成的圆锥体积最小。
这样转化之后可以看出直线的临界条件应当是经过其中一点。
三分圆锥半径R,因为要覆盖所有的点,让点(R, 0)与所有点连线,直线与Z轴交点即为H,H取其中最大的那个。
求一条直线,使所有点在这条直线的下方,直线与X轴和Z轴围成的三角形旋转形成的圆锥体积最小。
这样转化之后可以看出直线的临界条件应当是经过其中一点。
三分圆锥半径R,因为要覆盖所有的点,让点(R, 0)与所有点连线,直线与Z轴交点即为H,H取其中最大的那个。
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #define EPS 1e-9 using namespace std; const int MAXN = 10010; const double PI = acos(-1.0); struct point { double x, y; }; int N; point P[MAXN]; int dcmp( double a ) { if ( fabs(a) < EPS ) return 0; return a < 0 ? -1 : 1; } double GetH( double R ) { double maxH = 0.0; for ( int i = 0; i < N; ++i ) { double tmp = R * P[i].y / ( R - P[i].x ); if ( dcmp( tmp - maxH ) > 0 ) maxH = tmp; } return maxH; } int main() { while ( ~scanf( "%d", &N ) ) { double maxR = 0.0; for ( int i = 0; i < N; ++i ) { double x, y, z; scanf( "%lf%lf%lf", &x, &y, &z ); P[i].x = sqrt( x*x + y*y ); P[i].y = z; maxR = max( maxR, P[i].x ); } double low = maxR, high = 1e10; while ( dcmp( high - low ) > 0 ) { double mid = ( low + high ) / 2.0; double midmid = ( mid + high ) / 2.0; double midV = GetH( mid ) * mid * mid; double midmidV = GetH( midmid ) * midmid * midmid; if ( dcmp( midV - midmidV ) <= 0 ) high = midmid; else low = mid; } printf("%.3f %.3f\n", GetH(low), low ); } return 0; }
相关文章推荐
- UVA 1473 - Dome of Circus(三分+计算几何)
- UVa 1473 Dome of Circus(求凸包)
- G - Dome of Circus UVALive - 4986 (三分)
- 圆锥:转为平面几何 UVA 1473 Dome of Circus
- UVALive 4986 Dome of Circus(三分、凸包、凸性函数)
- Dome of Circus - UVa 1473 几何 凸包
- uva 1473 - Dome of Circus (几何 + 二分)
- uva 1473 - Dome of Circus
- hdoj 3756 Dome of Circus(三分)
- UVA 1473&LA 4986 - Dome of Circus
- HDU 3756 Dome of Circus(计算几何 + 三分)
- hdu 3756 || Dome of Circus || 2010 Northeastern European Regional Contest(三分)
- UVA1473 - Dome of Circus
- hdu 3756 Dome of Circus(三分)
- HDU 3756 Dome of Circus (三分)
- hdu 3756 Dome of Circus 三分
- Dome of Circus(三分)
- HDU 3756 Dome of Circus 三分
- 【三分】HDU3756 Dome of Circus
- ACM--steps--4.1.7--Dome of Circus(三分)