UVA 1473 - Dome of Circus(三分+计算几何)
2015-03-26 15:28
330 查看
这题先推下公式,很容易发现圆锥的体积和半径满足一个二次函数,所以可以用三分
于是三分半径即可
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 10005;
const double PI = acos(-1.0);
struct Point {
double x, y, z;
void read() {
scanf("%lf%lf%lf", &x, &y, &z);
}
} p
;
int n;
double gao(double r) {
double h = 0;
for (int i = 0; i < n; i++) {
double d = sqrt(p[i].x * p[i].x + p[i].y * p[i].y);
h = max(h, p[i].z / (r - d) * r);
}
return h;
}
int main() {
while (~scanf("%d", &n)) {
double l = 0, r = 1e20;
for (int i = 0; i < n; i++) {
p[i].read();
l = max(l, sqrt(p[i].x * p[i].x + p[i].y * p[i].y));
}
l += 1e-8;
for (int i = 0; i < 200; i++) {
double midl = (l * 2 + r) / 3;
double midr = (l + r * 2) / 3;
double h1 = gao(midl);
double h2 = gao(midr);
double s1 = PI * midl / 3 * midl * h1;
double s2 = PI * midr / 3 * midr * h2;
if (s1 > s2) l = midl;
else r = midr;
}
printf("%.3f %.3f\n", gao(l), l);
}
return 0;
}
于是三分半径即可
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 10005;
const double PI = acos(-1.0);
struct Point {
double x, y, z;
void read() {
scanf("%lf%lf%lf", &x, &y, &z);
}
} p
;
int n;
double gao(double r) {
double h = 0;
for (int i = 0; i < n; i++) {
double d = sqrt(p[i].x * p[i].x + p[i].y * p[i].y);
h = max(h, p[i].z / (r - d) * r);
}
return h;
}
int main() {
while (~scanf("%d", &n)) {
double l = 0, r = 1e20;
for (int i = 0; i < n; i++) {
p[i].read();
l = max(l, sqrt(p[i].x * p[i].x + p[i].y * p[i].y));
}
l += 1e-8;
for (int i = 0; i < 200; i++) {
double midl = (l * 2 + r) / 3;
double midr = (l + r * 2) / 3;
double h1 = gao(midl);
double h2 = gao(midr);
double s1 = PI * midl / 3 * midl * h1;
double s2 = PI * midr / 3 * midr * h2;
if (s1 > s2) l = midl;
else r = midr;
}
printf("%.3f %.3f\n", gao(l), l);
}
return 0;
}
相关文章推荐
- UVa 1473 - Dome of Circus 三分
- Dome of Circus - UVa 1473 几何 凸包
- uva 1473 - Dome of Circus (几何 + 二分)
- HDU 3756 Dome of Circus(计算几何 + 三分)
- G - Dome of Circus UVALive - 4986 (三分)
- 圆锥:转为平面几何 UVA 1473 Dome of Circus
- UVALive 4986 Dome of Circus(三分、凸包、凸性函数)
- UVa 1473 Dome of Circus(求凸包)
- UVa 10112 Myacm Triangles (枚举&计算几何)
- ZOJ 3203 计算几何+三分
- [BZOJ1857][Scoi2010]传送带(三分套三分+计算几何)
- HDU 3756 Dome of Circus 三分
- UVA 438 - The Circumference of the Circle(计算几何)
- UVA 12301 - An Angular Puzzle(计算几何)
- 【三分】HDU3756 Dome of Circus
- 100道动态规划——4 UVA 1331 Maximum Triangulation DP 计算几何
- UVA 1331 Minimax Triangulation [最优三角剖分] [dp] [计算几何]
- 计算几何专项:UVa 12307
- 计算几何专项:UVa 11437
- UVA 10652 Board Wrapping 计算几何