poj 2451 Uyuw's Concert(半平面交)
| Time Limit: 6000MS | Memory Limit: 65536K | |
| Total Submissions: 8580 | Accepted: 3227 |
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
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
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.
Source
【思路】
半平面交。
注意设置边界,输入向量方向和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(半平面交)的更多相关文章
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- poj 2451 Uyuw's Concert (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- poj 2451 Uyuw's Concert
[题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- POJ 2451 Uyuw's Concert(半平面交nlgn)
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- POJ 3384 放地毯【半平面交】
<题目链接> 题目大意: 给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠.问最多能覆盖多大空间,输出两个地毯的圆心坐标.多组解输出其中一个,题 ...
随机推荐
- SQL的定义与使用
一.SQL的定义 SQL(structured query language)即结构化查询语句,是关系数据库的标准语言. SQL的特点有: 1.综合统一 SQL集数据定义语言DDL.数据操作语言DML ...
- ubuntu server 安装
http://tigerlchen.iteye.com/blog/1765765 解决CDROM找不到的bug
- 【实习记】2014-09-26恢复linux下误删的ntfs盘中的文件
情景,ubuntu下把NTFS格式的盘中的“实习记”文件夹彻底删除了,追毁莫及,粗心觉不是一件好的事情. linux下回复ntfs盘下的文件不能用ext3grep,而使用debugfs命令实在 ...
- qwt6在Windows下Qt5的编译,安装,初步使用
今晚把qwt的编译,安装,初级使用放上来,以便需要的人,能更快部署好编程环境,不至于每次都像我这样花很多时间. 注意:Qtcreater使用的是什么编译器编译出来的,就要用那个编译器来编译qwt. 我 ...
- 系统重装后phpnow修复
最近在捣鼓wordpress,主题写了一半然后就重装了win8,在新系统里面访问127.0.0.1的时候出现无法访问的情况.主题写了一半,又不想重装wordpress导数据库这些繁琐的过程,于是,尝试 ...
- [转]maven插件的开发
原文链接: http://clojure.iteye.com/blog/1124188 另一篇文章 http://blog.csdn.net/csfreebird/article/details/77 ...
- ORA-01033 ORA-01109 ORA-01034 ORA-12514 ORA-24324 ORA-01041 ORA-01157 ORA-01110
客户数据库挂掉了 在plsql客户端使用普通账号登录时提示如下错误 因为好久没弄数据库了,慌了一小下. 接下来搜索过往的知识,回忆.在cli下输入了以下命令 sqlplus system/system ...
- css实现网页布局随滚轮变化响应移动
_position:absolute; _top:expression(eval(document.documentElement.scrollTop)); 1.第一句代码 _position:abs ...
- JDBC 基础知识总结
1. 何谓JDBC --- Java Database Connectivity. 由Sun 公司提供的访问数据库的一组java类和接口,用来对数据库进行链接.发送SQL语句.处理返回结果,为开发 ...
- 被windows“折磨”了一个礼拜
说是被windows折磨了一个礼拜,这话一点都不假!由于想彻底的卸载SQL Server而误删系统文件,导致系统重启之后持续蓝屏.无奈之下只能重装系统(心想,加入当初自己将系统备份的话,那该是多美好的 ...