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 放地毯【半平面交】
<题目链接> 题目大意: 给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠.问最多能覆盖多大空间,输出两个地毯的圆心坐标.多组解输出其中一个,题 ...
随机推荐
- IF EXIST: The syntax of the command is incorrect.
Batch 脚本中使用 IF EXIST 语句时,总是提示 The syntax of the command is incorrect. 原始 bat 脚本如下: ECHO OFF SET proj ...
- XCOPY: Access denied
用 XCOPY 拷贝文件,出现 “Access denied” 提示信息. 原因: 在如上拷贝的目标路径下,存在 ReadMe.txt, 并且是 只读 文件,这种情况下,需要增加一个 拷贝选项: /R ...
- ZeroMemory和memset的区别
摘自百度百科,保存为学习使用 ZeroMemory,是美国微软公司的软件开发包SDK中的一个宏. 其作用是用0来填充一块内存区域. 声明 void ZeroMemory( PVOID Destinat ...
- OpenJudge 2787 算24
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/2787/ 2.题目: 总时间限制: 3000m ...
- ASP.NET缓存 Cache
缓存介绍 如果每次进入页面的时候都查询数据库生成页面内容的话,如果访问量非常大,则网站性能会非常差,而如果只有第一次访问的时候才查询数据库生成页面内容,以后都直接输出内容,则能提高系统性能,这样无论多 ...
- /var子目录
/var子目录 目录 描述 /var/log/message 日志信息,按周自动轮询 /var/spool/cron/root 定时器配置文件目录,默认按用户命名 /var/log/secure 记录 ...
- ubuntu下编译安装apache
官网http://httpd.apache.org/download.cgi下载apache源码包后 /*解包*/ gzip -d httpd-2_x_NN.tar.gz tar -xf httpd- ...
- fork();
僵死进程: 父进程没有等待子进程,wait() 子进程会变成僵死进程. int main(int arg, char *args[]){ pid_t pid = fork();//调用fork产生一个 ...
- linux根目录详解
ubuntu 文件说明:http://tech.ccidnet.com/art/302/20080118/1347213_1.html/ 根目录 | |-boot/ 启动文件.所有与系统启动有关的 ...
- C语言-04函数
1.参数 参数注意点 1.形式参数:定义函数时函数名后面中的参数,简称形参 2.实际参数:调用函数式传入的具体数据,简称实参 3.实参个数必须等于形参个数 4.函数体内部不能定义和形参一样的变量 5. ...