Uyuw's Concert
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 8580   Accepted: 3227

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.

Source

POJ Monthly,Zeyuan Zhu

【思路】

半平面交。

注意设置边界,输入向量方向和eps选择,1e-10足够。

【代码】

 #include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
using namespace std; const int eps = 1e-; struct Pt {
double x,y;
Pt (double x=,double y=) :x(x),y(y) {}
};
typedef Pt vec; vec operator - (Pt a,Pt b) { return vec(a.x-b.x,a.y-b.y); }
vec operator + (vec a,vec b) { return vec(a.x+b.x,a.y+b.y); }
vec operator * (vec a,double x) { return vec(a.x*x,a.y*x); } double cross(Pt a,Pt b) { return a.x*b.y-a.y*b.x; } struct Line {
Pt p; vec v; double ang;
Line() {}
Line(Pt p,vec v) :p(p),v(v) { ang=atan2(v.y,v.x); }
bool operator < (const Line& rhs) const {
return ang < rhs.ang;
}
};
//p在l的左边
bool onleft(Line L,Pt p) { return cross(L.v,p-L.p)>; }
Pt getLineInter(Line a,Line b) {
vec u=a.p-b.p;
double t=cross(b.v,u)/cross(a.v,b.v);
return a.p+a.v*t;
} vector<Pt> HPI(vector<Line> L) {
int n=L.size();
sort(L.begin(),L.end());
int f,r;
vector<Pt> p(n) , ans;
vector<Line> q(n);
q[f=r=]=L[];
for(int i=;i<n;i++) {
while(f<r && !onleft(L[i],p[r-])) r--;
while(f<r && !onleft(L[i],p[f])) f++;
q[++r]=L[i];
if(fabs(cross(q[r].v,q[r-].v))<eps) {
r--;
if(onleft(q[r],L[i].p)) q[r]=L[i];
}
if(f<r) p[r-]=getLineInter(q[r-],q[r]);
}
while(f<r && !onleft(q[f],p[r-])) r--;
if(r-f<=) return ans;
p[r]=getLineInter(q[r],q[f]);
for(int i=f;i<=r;i++) ans.push_back(p[i]);
return ans;
}
vector<Line> L;
vector<Pt> p;
int n; int main() {
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
scanf("%d",&n);
double x1,y1,x2,y2;
for(int i=;i<n;i++) {
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
Pt a(x1,y1) , b(x2,y2);
L.push_back(Line(a,b-a));
}
Pt a(,),b(,),c(,),d(,);
L.push_back(Line(a,b-a));
L.push_back(Line(b,c-b));
L.push_back(Line(c,d-c));
L.push_back(Line(d,a-d));
p = HPI(L);
double ans=; int m=p.size();
for(int i=;i<m-;i++)
ans += cross(p[i]-p[],p[i+]-p[]);
printf("%.1lf",ans/);
return ;
}

poj 2451 Uyuw's Concert(半平面交)的更多相关文章

  1. POJ 2451 Uyuw's Concert (半平面交)

    题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...

  2. poj 2451 Uyuw's Concert (半平面交)

    2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...

  3. poj 2451 Uyuw's Concert

    [题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...

  4. POJ2451 Uyuw's Concert(半平面交)

    题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...

  5. POJ 2451 Uyuw's Concert(半平面交nlgn)

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...

  6. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  7. POJ 1279 Art Gallery(半平面交求多边形核的面积)

    题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...

  8. POJ 3335 Rotating Scoreboard(半平面交求多边形核)

    题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...

  9. POJ 3384 放地毯【半平面交】

    <题目链接> 题目大意: 给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠.问最多能覆盖多大空间,输出两个地毯的圆心坐标.多组解输出其中一个,题 ...

随机推荐

  1. 菜鸟的MySQL学习笔记(四)

    MySQL中的运算符和函数: 1.字符函数: 2.数值运算符与函数: 3.比较运算符与函数: 4.日期时间函数: 5.信息函数: 6.聚合函数: 7.加密函数等:   6-1.字符函数: CONCAT ...

  2. hibernate符合主键

    当有符合主键时,一方与多方的复合主键顺序必须一致: <set> <key> <column name="A" /> <column nam ...

  3. RM-Linux驱动--Watch Dog Timer(看门狗)驱动分析

    from:http://blog.csdn.net/geekcome/article/details/6595265 硬件平台:FL2440 内核版本:2.6.28 主机平台:Ubuntu 11,04 ...

  4. nginx Engine X静态网页服务器介绍

    Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. 反向代理(Reverse Proxy)方 ...

  5. PHP全局变量

    1.global 关键字 2.$GLOBALS 3.使用静态变量

  6. 使用cvs或svn从sourceforge上获取开源项目的方法[转载]

    著名开源软件网站(www.sourceforge.net)上面的开源项目,大部分使用的管理工具为cvs或svn. 这两种软件的代表客户端程序是wincvs和tortoiseSVN.   1.cvs C ...

  7. Poco之ftp获取文件列表以及下载文件

    #include <iostream>#include <string>#include <vector>#include <algorithm>#in ...

  8. WPF中嵌入Flash(ActiveX)

    1. 建立 WPF Application. 首先,建立一个名为 FlashinWPF 的 WPF Application 2. 设置 Window 属性. 在 XAML 中修改 Window 的属性 ...

  9. [swift]可选类型

    可选类型 <Swift权威指南>第2章千里之行始于足下——Swift语言基础,本章挑选了Swift语言的最基本特性加以介绍.尽管这些特性只占Swift全部特性的很少一部分,但却是所有的Sw ...

  10. 5个有用的.net profiling工具(转)

    我们有时需要对研发的软件程序进行性能测试,这时需要用到一些Profilers工具.下面列出5个有用的.net Profilers: 1. JetBrains dotTrace JetBrains do ...