HDOJ_ACM_Dome of Circus
2013-03-17 20:43
288 查看
[align=left]Problem Description[/align] A travelling circus faces a tough challenge in designing the dome for its performances. The circus has a number of shows that happen above the stage in the air under the dome. Various rigs, supports, and anchors must be installed over the stage, but under the dome. The dome itself must rise above the center of the stage and has a conical shape. The space under the dome must be air-conditioned, so the goal is to design the dome that contains minimal volume. You are given a set of n points in the space; (xi, yi, zi) for 1 ≤ i ≤ n are the coordinates of the points in the air above the stage that must be covered by the dome. The ground is denoted by the plane z = 0, with positive z coordinates going up. The center of the stage is on the ground at the point (0, 0, 0). The tip of the dome must be located at some point with coordinates (0, 0, h) with h > 0. The dome must have a conical shape that touches the ground at the circle with the center in the point (0, 0, 0) and with the radius of r. The dome must contain or touch all the n given points. The dome must have the minimal volume, given the above constraints. |
[align=left]Input[/align] The input begins with an integer T. The next T blocks each represents a case. The first line of each case contains a single integer number n (1 ≤ n ≤ 10 000) - the number of points under the dome. The following n lines describe points with three floating point numbers xi, yi, and zi per line - the coordinates of i-th point. All coordinates do not exceed 1000 by their absolute value and have at most 2 digits after decimal point. All zi are positive. There is at least one point with non-zero xi or yi. |
[align=left]Output[/align] For each case , write to the output file a single line with two floating point numbers h and r - the height and the base radius of the dome. The numbers must be precise up to 3 digits after decimal point. |
[align=left]Sample Input[/align]3 1 1.00 0.00 1.00 2 1.00 0.00 1.00 0.00 1.50 0.50 3 1.00 0.00 1.00 0.00 1.50 0.50 -0.50 -0.50 1.00 |
[align=left]Sample Output[/align]3.000 1.500 2.000 2.000 2.000 2.000 |
Code#include <stdio.h> #include <math.h> #define N 10000 struct Point { double x; double y; double z; }points[N + 5]; int count; //everytime the number of points double a[N + 5], b[N + 5]; //array a is r, array b is h double getMaxH(double R) { double max, h; int i; max = 0; for (i = 1; i <= count; i++) { h = R * b[i] / (R - a[i]); if (h > max) max = h; } return max; } double f(double r, double h) { return r * r * h; } void main() { int i, n; double rlow, rhigh, rmid1, rmid2, max, h1, h2; max = 0; scanf("%d", &n); while (n--) { scanf("%d", &count); for (i = 1; i <= count; i++) { scanf("%lf %lf %lf", &points[i].x, &points[i].y, &points[i].z); a[i] = sqrt (points[i].x * points[i].x + points[i].y * points[i].y); b[i] = points[i].z; if (a[i] > max) max = a[i]; } rlow = max; rhigh = 1e6; while (rhigh - rlow >= 1e-6) { rmid1 = (rhigh + rlow) / 2; rmid2 = (rhigh + rmid1) / 2; h1 = getMaxH(rmid1); h2 = getMaxH(rmid2); if (f(rmid1, h1) < f(rmid2, h2)) rhigh = rmid2; else rlow = rmid1; } printf("%.3lf %.3lf\n", h1, rmid1); } } |
Idea To begin with, u should reduce the X-Y-Z to X-Z, by using r = sqrt(x * x + y * y) Secondly, u should prove that when r increase, then v will reduce, then when r reduce, the v will reduce. Note, maybe u will get the value of the k, I try my best to use the value, but it's proved that it's no use. Last, u can use the trichotomy to divide the R. Note, u should count all the point so that u can get the max h, which means u contain all the points. |
Key point Firstly, u should write down the whole codes on the paper so that u can save the time to debug. |
相关文章推荐
- ACM--steps--4.1.7--Dome of Circus(三分)
- hdoj 3756 Dome of Circus(三分)
- HDOJ HDU 1201 18岁生日 ACM 1201 IN HDU
- HDOJ 1233 HDU 1233 还是畅通工程 ACM 1233 IN HDU
- HDOJ 1555 HDU 1555 How many days? ACM 1555 IN HDU
- HDOJ 2714 HDU 2714 ISBN ACM 2714 IN HDU
- HDOJ_ACM_母牛的故事
- HDOJ_ACM_Bone Collector
- ACM HDOJ 1753 (大明A+B)
- ACM HDOJ 1151 (Air Raid)
- 【ACM】HDOJ 1009 FatMouse' Trade
- 杭电ACM HDOJ 2143 box
- 2016 ACM/ICPC Asia Regional Shenyang Online && hdoj5901 Count primes Lehmer
- HDOJ_ACM_逃离迷宫
- HDOJ_ACM_N皇后问题
- ACM HDOJ 汉诺塔III
- 《动态规划》hdoj acm 3.2.4 最长有序子序列
- hdoj problem 5011Game(博弈论之尼姆博弈&&ACM模板)
- hdu 3756 Dome of Circus 三分
- ACM-HDOJ 2006 Asia Regional Shanghai