【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.

avatar

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:
avatar
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.


Solution
半平面交裸题,直接上模板就好了,至于那些公式还是背代码大法好啊
Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <ctime>

using namespace std;

#define rep(i,l,r) for(i=l;i<=r;i++)
#define ser(i,r,l) for(i=r;i>=l;i--)
#define INF 20005
#define inf 1000000007
#define eps 1e-6

typedef long long ll;
priority_queue<int >QwQ;

struct Point {
    double x,y;
}a[INF];
struct Line {
    Point a,b;
    double angle;//极角
}f[INF],q[INF];
int n,cnt=0;
double ans=0;
int read()
{
    int k=0,f=1;
    char ch;
    while(ch<'0' || ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')k=(k<<1)+(k<<3)+ch-'0',ch=getchar();
    return k*f;
}
double operator *(Point A,Point B)
{
    return A.x*B.y-A.y*B.x;
}
double Cross(Point A,Point B,Point C)
{
    return (A.x-C.x)*(B.y-C.y)-(A.y-C.y)*(B.x-C.x);
}
int check(double A)
{
    if(fabs(A)<=eps)return 0;
    if(A>0)return 1;
    return -1;
}
bool cmp(Line A,Line B)
{
    if(check(A.angle-B.angle)!=0)return check(B.angle-A.angle)>0;
    return check(Cross(B.b,B.a,A.a))>0;
}
Point Node(Line A,Line B)
{
    Point C;
    double k,t1,t2;
    t1=Cross(A.b,B.b,B.a);
    t2=Cross(B.b,A.a,B.a);
    k=t1/(t1+t2);
    C.x=A.b.x+(A.a.x-A.b.x)*k;
    C.y=A.b.y+(A.a.y-A.b.y)*k;
    return C;
}
int Judge(Line A,Line B,Line C)
{
    Point P;
    P=Node(A,B);
    return check(Cross(C.a,C.b,P))<0; 
}
void HPC()
{
    int i,j,k=1,top,last;
    top=2,last=1;
    rep(i,2,n)
     if(check(f[i-1].angle-f[i].angle)!=0){
         f[++k]=f[i];
     }
     else f[k]=f[i];
    n=k;
    q[1]=f[1],q[2]=f[2];
    rep(i,3,n){
        while(top>last && Judge(q[top],q[top-1],f[i]))top--;
        while(top>last && Judge(q[last],q[last+1],f[i]))last++;
        q[++top]=f[i];
    }
    while(top>last && Judge(q[top],q[top-1],q[last]))top--;
    while(top>last && Judge(q[last],q[last+1],q[top]))last++;
    q[++top]=q[last];
    rep(i,last,top-1)a[++cnt]=Node(q[i],q[i+1]);
    a[++cnt]=a[1];
}
void Area()
{
    int i,j,k;
    if(cnt<3)return ;
    rep(i,1,cnt-1)ans+=a[i]*a[i+1];
    ans=fabs(ans)/2.0;
    printf("%.1lf\n",ans);
}
void init()
{
    int i,j,k;
    n=read();
    rep(i,1,n)scanf("%lf%lf%lf%lf",&f[i].a.x,&f[i].a.y,&f[i].b.x,&f[i].b.y);
    f[++n].a.x=0,f[n].a.y=0,f[n].b.x=10000,f[n].b.y=0;
    f[++n].a.x=0,f[n].a.y=10000,f[n].b.x=0,f[n].b.y=0;
    f[++n].a.x=10000,f[n].a.y=0,f[n].b.x=10000,f[n].b.y=10000;
    f[++n].a.x=10000,f[n].a.y=10000,f[n].b.x=0,f[n].b.y=10000;
    rep(i,1,n)f[i].angle=atan2((f[i].b.y-f[i].a.y),(f[i].b.x-f[i].a.x));
    sort(f+1,f+n+1,cmp);
}
void work()
{
    int i,j,k;
    HPC();
    Area();
}
int main()
{
    init();
    work();
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值