UVa 1473 Dome of Circus(求凸包)
2014-10-14 19:31
232 查看
暂存。WA
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <algorithm> #define INF 0x7f7f7f7f using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const int maxn = 10010; int sig(double argu) { return (argu > eps) - (argu < -eps); } typedef struct Point { double x, y; Point (double _x = 0.0, double _y = 0.0): x(_x), y(_y) {} Point operator +(const Point &argu) const { return Point(x + argu.x, y + argu.y); } Point operator -(const Point &argu) const { return Point(x - argu.x, y - argu.y); } Point operator *(const double k) const { return Point(x * k, y * k); } Point operator /(const double k) const { return Point(x / k, y / k); } double operator ^(const Point &argu) const { return (x * argu.y - y * argu.x); } bool operator <(const Point &argu) const { if(sig(y - argu.y) == 0) return x < argu.x; else return y < argu.y; } }Vector; int n; Point pp[maxn], minp; double x, y, z; int q[maxn], top; double h, r; double s[maxn], best; int id; bool cmp(Point a, Point b) { double anga = atan2(a.y - minp.y, a.x - minp.x); double angb = atan2(b.y - minp.y, b.x - minp.x); return anga < angb; } double Cross(Point a, Point b, Point c) { return ((b - c) ^ (a - c)); } void GetHull() { for(int i = 2; i < n; i++) { while(top > 1 && Cross(pp[i], pp[q[top - 1]], pp[q[top - 2]]) < 0) top--; q[top++] = i; } } void GetBV(int id) { if(id == 0) { best = pi * (1.5 * pp[0].x) * (1.5 * pp[0].x) * pp[0].y; h = 3.0 * pp[0].y; r = 1.5 * pp[0].x; } else if(id == 1) { if(best < pi * (1.5 * pp[q[1]].x) * (1.5 * pp[q[1]].x) * pp[q[1]].y) { best = pi * (1.5 * pp[q[1]].x) * (1.5 * pp[q[1]].x) * pp[q[1]].y; h = 3.0 * pp[q[1]].y; r = 1.5 * pp[q[1]].x; } } else { double k = atan2(2 * pp[q[id]].y, -pp[q[id]].x); double kl = atan2(pp[q[id]].y - pp[q[id - 1]].y, pp[q[id]].x - pp[q[id - 1]].x); double kr = atan2(pp[q[id + 1]].y - pp[q[id]].y, pp[q[id + 1]].x - pp[q[id]].x); if(sig(kr - pi) >= 0 && sig(k - kr) >= 0) k = kr; if(sig(kl - pi) >= 0 && sig(kl - k) >= 0) k = kl; double tmph = x * tan(k) + y; double tmpr = x * y / tan(k); double tmpv = pi * (1.5 * tmpr) * (1.5 * tmpr) * tmph; if(best < tmpv) { best = tmpv; h = tmph; r = tmpr; } } } int main() { //freopen("1473.in", "r", stdin); while(~scanf("%d", &n)) { for(int i = 0; i < n; i++) { scanf("%lf%lf%lf", &x, &y, &z); pp[i] = Point(sqrt(x * x + y * y), z); } minp = pp[0]; for(int i = 1; i < n; i++) minp = min(minp, pp[i]); sort(pp, pp + n, cmp); q[0] = 0; top = 1; GetBV(0); if(n > 1) { q[1] = 1; top++; GetBV(1); if(n > 2) { GetHull(); for(int i = 0; i < top; i++) { double base = (pp[q[i]].x - pp[q[(i + 1) % top]].x); if(sig(base) != 0) { double slope = (pp[q[i]].y - pp[q[(i + 1) % top]].y) / base; if(slope < 0.0) GetBV(i); } } } } printf("%.3lf %.3lf\n", h, r); } return 0; }
相关文章推荐
- Dome of Circus - UVa 1473 几何 凸包
- UVALive 4986 Dome of Circus(三分、凸包、凸性函数)
- uva 1473 - Dome of Circus (几何 + 二分)
- UVa 1473 - Dome of Circus 三分
- UVA 1473 - Dome of Circus(三分+计算几何)
- 圆锥:转为平面几何 UVA 1473 Dome of Circus
- UVA1473 - Dome of Circus
- uva 1473 - Dome of Circus
- G - Dome of Circus UVALive - 4986 (三分)
- UVA 1473&LA 4986 - Dome of Circus
- uva 10652 Board Wrapping(Graham凸包算法)
- UVA 10652 - Board Wrapping(二维凸包)
- UVA 10173 最小矩形覆盖(凸包+旋转卡壳)
- UVA 11626 Convex Hull(凸包:模板题)
- UVa 109 SCUD Busters (凸包面积&判断点是否在凸包内部)
- (beginer) 凸包 UVA 1303 - Wall
- UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)
- 凸包 【uva11168】 Airport
- UVALive - 7461 Separating Pebbles 凸包+线段相交
- UVA 132 Bumpy Objects【凸包变形】【附图】