poj 2451 Uyuw's Concert
【题目描述】
Remmarguts公主成功地解决了象棋问题。作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场。
这个位于自由三角洲联合王国(UDF,United Delta of Freedom)最繁华地带的广场是一个坐标范围[0,10000]*[0,10000]的正方形。有一些长椅已经固定在广场上许多年了,但是杂乱无章。见下图:

我们有三张长椅,并且观众面对的方向已经用箭头画出。这些椅子年代久远,并且沉重得无法移动。Remmarguts公主让广场现在的主人UW先生在广场上修建一个大的舞台。这个舞台应当尽可能大,但必须确保在任意长椅上任意位置的观众不必转身就能看到舞台(也就是说舞台必须在长椅所在直线的观众朝向那一侧)。
为了简化问题,舞台的高度可以任意高来确保只要你面向舞台所在的那一侧,你就能看到舞台上的歌唱家/画家——Uyuw,即使你的面前有数千张长椅。
作为一名脑残粉,你能告诉他们舞台的最大面积吗?
【输入格式】
输入包含不超过10组数据。
每组数据格式如下:
第一行有一个整数N(N<=20000),代表长椅的数量。
接下来有N行,每行有4个整数x1,y1,x2,y2,代表一张长椅。这张长椅是以(x1,y1)和(x2,y2)为端点的线段,并且面向其左侧。一个点(x,y)在线段左侧是指(x-x1)*(y-y2)-(x-x2)*(y-y1)>=0.
【输出格式】
对每组数据输出一个一个实数,即舞台的最大面积。精确到1位小数。你的答案被认为是正确的当且仅当它与标准答案之差小于0.2。
【样例输入】
3
10000 10000 0 5000
10000 5000 5000 10000
0 5000 5000 0
【样例输出】
54166666.7
【提示】
样例如下:

建议你采用Pascal中的Extended类型或者C/C++中的long double类型来避免精度误差。不过标程仅仅用了double。
半平面交模板(太坑了)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double ld;
struct point
{
ld x,y;
point(){}
point(ld _x,ld _y) {x=_x,y=_y;}
}p[];
struct Line
{
point a,b;
ld angle;
Line(){}
Line(point _a,point _b) {a=_a,b=_b;}
}line[],sta[];
ld eps=1e-,ans;
int n,cnt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(ld x)
{
if (x>eps) return ;
if (x<-eps) return -;
return ;
}
ld cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
ld getangle(Line l)
{
return atan2(l.b.y-l.a.y,l.b.x-l.a.x);
}
point inter(Line u,Line v)
{
double k1=(cross((u.b-v.a),(v.b-v.a)));
double k2=(cross((v.b-v.a),(u.a-v.a)));
double t=k1/(k1+k2);
return point(u.b.x+(u.a.x-u.b.x)*t,u.b.y+(u.a.y-u.b.y)*t);
}
bool cmp(Line u,Line v)
{
int t=dcmp(u.angle-v.angle);
if (t) return t<;
return dcmp(cross(u.a-v.b,v.a-v.b))>;
}
bool judge(Line a,Line b,Line c)
{
point p=inter(b,c);
return dcmp(cross(a.a-p,a.b-p))<;
}
void HPT()
{int i,head,tail;
sort(line+,line+n+,cmp);
int tmp=;
for (i=;i<=n;i++)
if (dcmp(line[i].angle-line[i-].angle)!=)
line[++tmp]=line[i];
n=tmp;
head=,tail=;
sta[]=line[];sta[]=line[];
for (i=;i<=n;i++)
{
while (tail->=head&&judge(line[i],sta[tail],sta[tail-])) tail--;
while (head+<=tail&&judge(line[i],sta[head+],sta[head])) head++;
tail++;
sta[tail]=line[i];
}
while (tail->=head&&judge(sta[head],sta[tail],sta[tail-])) tail--;
while (head+<=tail&&judge(sta[tail],sta[head+],sta[head])) head++;
cnt=;
if (tail-head<=) return;
for (i=head;i<tail;i++)
{
p[++cnt]=inter(sta[i],sta[i+]);
}
if (tail>head+)
p[++cnt]=inter(sta[head],sta[tail]);
}
int main()
{
int i;
while (cin>>n)
{
n+=;
line[]=Line(point(,),point(,));
line[]=Line(point(,),point(,));
line[]=Line(point(,),point(,));
line[]=Line(point(,),point(,));
line[].angle=getangle(line[]);
line[].angle=getangle(line[]);
line[].angle=getangle(line[]);
line[].angle=getangle(line[]);
for (i=;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y);
line[i].angle=getangle(line[i]);
}
HPT();
ans=;
for (i=;i<cnt;i++)
{
ans+=cross(p[i]-p[],p[i+]-p[])/2.0;
}
ans=fabs(ans);
printf("%.1lf\n",ans);
}
return ;
}
poj 2451 Uyuw's Concert的更多相关文章
- poj 2451 Uyuw's Concert (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- poj 2451 Uyuw's Concert(半平面交)
Uyuw's Concert Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8580 Accepted: 3227 De ...
- POJ 2451 Uyuw's Concert(半平面交nlgn)
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...
- bzoj 2451 Uyuw's Concert
裸的半平面交.感觉这些东西,纯属在考代码能力啊.. #include<cstdio> #include<algorithm> #include<cmath> #de ...
- 计算几何模板 (bzoj 1336,poj 2451 ,poj3968)
poj 3968 (bzoj 2642) 二分+半平面交,每次不用排序,这是几个算几版综合. #include<iostream> #include<cstdio> #incl ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- Uyuw's Concert POJ2451
裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...
- [poj2451]Uyuw's Concert
半平面交滴裸题,但是要求nlogn,练练手 #include<iostream> #include<cstdio> #include<cmath> #include ...
随机推荐
- JavaScript Alert 函数执行顺序问题
* { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...
- 从Firefox升级说学习方法
今天早上,打开PortableAPPs时,它提示我升级FireFox,跟往常一样我没考虑就升级了. 打开Firefox 57神速,很是惊喜,打开后发现悲剧了,自己(通过下载插件)定制的功能都不能使用了 ...
- (转)如何在Eclipse中查看JDK类库的源代码
在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 “window”-> "Preferences" -> "Java" -> & ...
- 故障公告:IIS应用程序池停止工作造成博客站点无法访问
非常抱歉,今天凌晨博客站点负载均衡中所有3台服务器的IIS应用程序池突然停止工作,造成 1:20-7:45 左右博客站点无法正常访问,由此给您带来很大的麻烦,请您谅解. 服务器操作系统是 Window ...
- babel基本用法
babel-cli babel-cli是本地使用编译js文件 1.安装: cnpm i babel-cli babel-preset-env -D 2.配置packjson: "script ...
- WebApi 接口返回值类型详解 ( 转 )
使用过Webapi的园友应该都知道,Webapi的接口返回值主要有四种类型 void无返回值 IHttpActionResult HttpResponseMessage 自定义类型 此篇就围绕这四块分 ...
- Python内置函数(35)——next
英文文档: next(iterator[, default]) Retrieve the next item from the iterator by calling its __next__() m ...
- jquery 实时监听输入框值变化方法
$('.offers-number').bind('input propertychange', function (a, b) { var value = $(this).val() if (!va ...
- LXC学习实践(2)安装LXC
1.准备工作: yum install gcc yum install libcap-devel yum install libcgroup 2.安装LXC 下载源代码:sourceforge.net ...
- python入门(5)使用文件编辑器编写代码并保存执行
python入门(5)使用文件编辑器编写代码并保存执行 两款文本编辑器: 一个是Sublime Text,免费使用,但是不付费会弹出提示框: 一个是Notepad++,免费使用,有中文界面: 请注意, ...