现在的位置: 首页 > 综合 > 正文

UVa 1473 Dome of Circus(求凸包)

2019年02月12日 ⁄ 综合 ⁄ 共 2217字 ⁄ 字号 评论关闭

暂存。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;
}

抱歉!评论已关闭.