Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 6830 | Accepted: 2688 |
Description
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
Output
Sample Input
3 10000 10000 0 5000 10000 5000 5000 10000 0 5000 5000 0
Sample Output
54166666.7
Hint
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.
/*
題意:給出一些向量,求出圍成的多邊形的核的面積
朱澤圓專爲他那篇nlog(n)算法解決半平面交問題的論文而出的題目,至今不會自己寫(汗顏,自己全是套模板).
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>
#define LL long long
#define IT __int64
#define zero(x) fabs(x)<eps
#define mm(a,b) memset(a,b,sizeof(a))
const int INF=0x7fffffff;
const double inf=1e8;
const double eps=1e-10;
const double PI=acos(-1.0);
const int Max=20001;
using namespace std;
struct point
{
double x;
double y;
}p[Max];
struct Segment
{
point s;
point e;
double angle;
void get_angle()
{
angle=atan2(e.y-s.y,e.x-s.x);//得到斜率對應的角度
}
}seg[Max];
int m;
//叉積爲正說明,p2在p0-p1的左側
double xmul(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
point Get_Intersect(Segment s1,Segment s2)//求交點
{
double u,v;
u=xmul(s1.s,s1.e,s2.s);
v=xmul(s1.e,s1.s,s2.e);
point res;
res.x=(s2.s.x*v+s2.e.x*u)/(u+v);
res.y=(s2.s.y*v+s2.e.y*u)/(u+v);
return res;
}
bool cmp(Segment s1,Segment s2)
{
if(s1.angle>s2.angle) //先按極角排序
return true;
else if(zero(s1.angle-s2.angle)&&xmul(s2.s,s2.e,s1.e)>-eps) //極角相等,內側的在前
return true;
return false;
}
void initial()//初始化
{
seg[0].s.x=0;
seg[0].s.y=0;
seg[0].e.x=10000;
seg[0].e.y=0;
seg[0].get_angle();
seg[1].s.x=10000;
seg[1].s.y=0;
seg[1].e.x=10000;
seg[1].e.y=10000;
seg[1].get_angle();
seg[2].s.x=10000;
seg[2].s.y=10000;
seg[2].e.x=0;
seg[2].e.y=10000;
seg[2].get_angle();
seg[3].s.x=0;
seg[3].s.y=10000;
seg[3].e.x=0;
seg[3].e.y=0;
seg[3].get_angle();
}
void HalfPlaneIntersect(Segment seg[],int n)//半平面交模版(nlog(n))
{
sort(seg,seg+n,cmp);
int temp=1;
for(int i=1; i<n; i++)
{
if(!zero(seg[i].angle-seg[temp-1].angle))
seg[temp++]=seg[i];
}
n=temp;
Segment deq[Max];
deq[0]=seg[0];
deq[1]=seg[1];
int head=0,tail=1;
for(int i=2; i<n; i++)
{
while(head<tail&&xmul(seg[i].s,seg[i].e,Get_Intersect(deq[tail],deq[tail-1]))<-eps)
tail--;
while(head<tail&&xmul(seg[i].s,seg[i].e,Get_Intersect(deq[head],deq[head+1]))<-eps)
head++;
deq[++tail]=seg[i];
}
while(head<tail&&xmul(deq[head].s,deq[head].e,Get_Intersect(deq[tail],deq[tail-1]))<-eps)
tail--;
while(head<tail&&xmul(deq[tail].s,deq[tail].e,Get_Intersect(deq[head],deq[head+1]))<-eps)
head++;
if(head==tail)
return;
m=0;
for(int i=head; i<tail; i++)
p[m++]=Get_Intersect(deq[i],deq[i+1]);
if(tail>head+1)
p[m++]=Get_Intersect(deq[head],deq[tail]);
}
double Get_area(point p[],int &n)//叉積求多邊形面積
{
double area=0;
for(int i=1; i<n-1; i++)
area+=xmul(p[0],p[i],p[i+1]);
return fabs(area)/2.0;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
initial();//初始化
for(int i=4; i<n+4; i++)
{
scanf("%lf%lf%lf%lf",&seg[i].s.x,&seg[i].s.y,&seg[i].e.x,&seg[i].e.y);
//cin>>seg[i].s.x>>seg[i].s.y>>seg[i].e.x>>seg[i].e.y;
seg[i].get_angle();
}
HalfPlaneIntersect(seg,n+4);
printf("%.1lf\n",Get_area(p,m));
//cout<<setprecision(1)<<setiosflags(ios::fixed)<<Get_area(p,m)<<endl;
}
return 0;
}