POJ 2451 Uyuw's Concert

来源:互联网 发布:php用户登录验证 编辑:程序博客网 时间:2024/05/16 01:47

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

310000 10000 0 500010000 5000 5000 100000 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. 

Source

POJ Monthly,Zeyuan Zhu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

半平面交~

用G++交WA了一晚上,用C++交就过了……这是什么原理?

double operator *的时候居然写成了返回值bool……


#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>using namespace std;int n,tot,bot,top;double ans;struct node1{double x,y;}k[20011];struct node{node1 a,b;double ang;}a[20011],q[20011];double operator * (node1 u,node1 v){return u.x*v.y-u.y*v.x;}node1 operator - (node1 u,node1 v){node1 kkz;kkz.x=u.x-v.x;kkz.y=u.y-v.y;return kkz;}bool operator < (node u,node v){return u.ang==v.ang ? (v.b-u.a)*(v.a-u.a)>0:u.ang<v.ang;}node1 chan(node u,node v){double k1=(u.b-v.a)*(v.b-v.a),k2=(v.b-v.a)*(u.a-v.a),t=k1/(k1+k2);node1 z;z.x=u.b.x+(u.a.x-u.b.x)*t;z.y=u.b.y+(u.a.y-u.b.y)*t;return z;}bool jud(node u,node v,node k){node1 z=chan(u,v);return (k.a-z)*(k.b-z)<0; }void cal(){top=1;bot=0;for(int i=1;i<=n;i++){  if(a[i].ang!=a[i-1].ang) tot++;  a[tot]=a[i];}q[0]=a[1];q[1]=a[2];n=tot;for(int i=3;i<=n;i++){while(bot<top && jud(q[top],q[top-1],a[i])) top--;while(bot<top && jud(q[bot],q[bot+1],a[i])) bot++;q[++top]=a[i];}while(bot<top && jud(q[top],q[top-1],q[bot])) top--;while(bot<top && jud(q[bot],q[bot+1],q[top])) bot++;q[top+1]=q[bot];tot=0;for(int i=bot;i<=top;i++) k[++tot]=chan(q[i],q[i+1]);}int main(){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%lf%lf%lf%lf",&a[i].a.x,&a[i].a.y,&a[i].b.x,&a[i].b.y);a[++n].a.x=0;a[n].a.y=10000;a[n].b.x=0;a[n].b.y=0;a[++n].a.x=10000;a[n].a.y=10000;a[n].b.x=0;a[n].b.y=10000;a[++n].a.x=10000;a[n].a.y=0;a[n].b.x=10000;a[n].b.y=10000;a[++n].a.x=0;a[n].a.y=0;a[n].b.x=10000;a[n].b.y=0;for(int i=1;i<=n;i++) a[i].ang=atan2(a[i].b.y-a[i].a.y,a[i].b.x-a[i].a.x);sort(a+1,a+n+1);cal();if(tot>=3){k[++tot]=k[1];for(int i=1;i<=tot;i++) ans+=k[i]*k[i+1];ans=fabs(ans)/2;}printf("%.1lf\n",ans);return 0;}


1 0