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. IOS 学习笔记 2015-04-10 OC-常用常量

    一 常用常量 (I) 关于按钮 UIControlState--->按钮状态 A UIControlStateNormal 默认状态 常规状态显现 B UIControlStateHighlig ...

  2. js清空前后空格

    function trim(sValue){                var lastValue=this.replace(/(^\s*)|(\s*$)/g,"");     ...

  3. SQLite学习第02天:数据类型

    参考资料:http://www.w3cschool.cc/sqlite/sqlite-data-types.html 在SQLite中,数据类型的概念看起来很模糊,刚开始接触感觉跟C语言提供的数据类型 ...

  4. ASP.NET MVC5 easyui 之 treegrid 初用记录

    菜鸟初次使用,参考论坛中介绍的方法仍走了一些弯路,把自己遇到的问题记录下来. 1.必须定义根节点: 2.根节点一个或多个均可: 4.根节点的父节点属性不必定义,或者定义为0: 5.各级子节点的父节点属 ...

  5. 深入了解overflow

    1.如果overflow-x与overflow-y值不同   其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...

  6. 移动端REM布局方案

    引用http://www.w3cplus.com/mobile/lib-flexible-for-html5-layout.html的方案 下载地址https://github.com/hupan50 ...

  7. ~/.vimrc config

    runtime! debian.vim "设置编码 set encoding=utf- set fencs=utf-,ucs-bom,shift-jis,gb18030,gbk,gb2312 ...

  8. 股票API

    实时股票数据接口大全 股票数据的获取目前有如下两种方法可以获取:1. http/javascript接口取数据2. web-service接口 1.http/javascript接口取数据 1.1Si ...

  9. ASP.NET注意事项

    1.服务器上bin目录下面的dll备份的时候,第一个点号之前的名字不能是一样的,否则会报错. 2.

  10. JS单元测试框架:QUnit

    QUnit:jQuery的单元测试框架,但不仅限于jQuery(从这个工具不需要引用jquery.js可以看出) index.html <!-- 官网 http://qunitjs.com/ - ...