poj 2451:Uyuw's Concert(半平面交模板)

Description

Prince Remmarguts solved the CHESS puzzle successfully. As an award, Uyuw planned to hold a concert in a huge piazza named after its great designer Ihsnayish. 

The piazza in UDF - United Delta of Freedom’s downtown was a square of [0, 10000] * [0, 10000]. Some basket chairs had been standing there for years, but in a terrible mess. Look at the following graph. 

In this case we have three chairs, and the audiences face the direction as what arrows have pointed out. The chairs were old-aged and too heavy to be moved. Princess Remmarguts told the piazza's current owner Mr. UW, to build a large stage inside it. The stage must be as large as possible, but he should also make sure the audience in every position of every chair would be able to see the stage without turning aside (that means the stage is in the forward direction of their own). 

To make it simple, the stage could be set highly enough to make sure even thousands of chairs were in front of you, as long as you were facing the stage, you would be able to see the singer / pianist – Uyuw. 

Being a mad idolater, can you tell them the maximal size of the stage?

Input

In the first line, there's a single non-negative integer N (N <= 20000), denoting the number of basket chairs. Each of the following lines contains four floating numbers x1, y1, x2, y2, which means there’s a basket chair on the line segment of (x1, y1) – (x2, y2), and facing to its LEFT (That a point (x, y) is at the LEFT side of this segment means that (x – x1) * (y – y2) – (x – x2) * (y – y1) >= 0).

Output

Output a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.

Sample Input

3
10000 10000 0 5000
10000 5000 5000 10000
0 5000 5000 0

Sample Output

54166666.7

Hint

Sample input is the same as the graph above, while the correct solution for it is as below: 

I suggest that you use Extended in pascal and long double in C / C++ to avoid precision error. But the standard program only uses double. 


题解:半平面交模板。。注意输入为小数。


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int Maxn=1e5+50;
int n,cnt,tot;
double ans;
struct point
{
	double x,y;
	point(double x=0,double y=0):x(x),y(y){}
	friend inline point operator -(const point &a,const point &b)
	{
		return point(a.x-b.x,a.y-b.y);
	}
	friend inline double operator *(const point &a,const point &b)
	{
		return a.x*b.y-a.y*b.x;
	}
}p[Maxn];
struct line
{
	point a,b;
	double slop;
	friend inline bool operator <(const line &a,const line &b)
	{
		if(a.slop!=b.slop)return a.slop<b.slop;
		return (a.b-a.a)*(b.b-a.a)>0;
	}
}l[Maxn],q[Maxn];
inline point inter(line a,line b)
{
	double k1=(b.b-a.a)*(a.b-a.a);
	double k2=(a.b-a.a)*(b.a-a.a);
	double t=k1/(k1+k2);
	return point(b.b.x+(b.a.x-b.b.x)*t,b.b.y+(b.a.y-b.b.y)*t);
}
inline bool judge(line a,line b,line c)
{
	point _=inter(a,b);
	return (c.b-c.a)*(_-c.a)<0;
}

inline void hpi()
{
	for(int i=1;i<=cnt;i++)
			l[i].slop=atan2(l[i].b.y-l[i].a.y,l[i].b.x-l[i].a.x);
	sort(l+1,l+cnt+1);
	l[++tot]=l[1];
	for(int i=2;i<=cnt;i++)
	{
		if(l[i].slop!=l[i-1].slop)tot++;
		l[tot]=l[i];
	}
	int L=1,R=0;
	q[++R]=l[1],q[++R]=l[2];
	for(int i=3;i<=tot;i++)
	{
		while(L<R&&judge(q[R-1],q[R],l[i]))R--;
		while(L<R&&judge(q[L+1],q[L],l[i]))L++;
		q[++R]=l[i];
	}
	while(L<R&&judge(q[R-1],q[R],q[L]))R--;
	while(L<R&&judge(q[L+1],q[L],q[R]))L++;
	q[++R]=q[L];tot=0;
	for(int i=L;i<R;i++)
	{
		p[++tot]=inter(q[i],q[i+1]);
	}
}

inline void getans()
{
	p[tot+1]=p[1];
	for(int i=1;i<=tot;i++)
	{
		ans+=p[i]*p[i+1];
	}
	ans=fabs(ans)/2.0;
}
inline void pre()
{
	l[++cnt].a=point(0,0),l[cnt].b=point(10000,0);
	l[++cnt].a=point(10000,0),l[cnt].b=point(10000,10000);
	l[++cnt].a=point(10000,10000),l[cnt].b=point(0,10000);
	l[++cnt].a=point(0,10000),l[cnt].b=point(0,0);
}
int main()
{
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		double x1,y1,x2,y2;
		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
		l[++cnt].a=point(x1,y1),l[cnt].b=point(x2,y2);
	}
	hpi();
	getans();
	printf("%.1f",ans);
	return 0;
}



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值