[poj2451]Uyuw's Concert
半平面交滴裸题,但是要求nlogn,练练手
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MN 50000
#define eps 1e-17
#define ld long double
using namespace std;
inline int read()
{
int x = , f = ; char ch = getchar();
while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
} struct P
{
ld x,y;
P(ld _x=,ld _y=):x(_x),y(_y){}
P operator +(P b){return P(x+b.x,y+b.y);}
P operator -(P b){return P(x-b.x,y-b.y);}
P operator *(ld b){return P(x*b,y*b);}
ld operator^(P b){return x*b.y-b.x*y;}
}p[MN+];
struct L
{
P p,v;ld slop;
L(){}
L(P x,P y):p(x),v(y){slop=atan2(y.y,y.x);}
P operator *(L y){P b=p-y.p;ld t=(y.v^b)/(v^y.v);return p+v*t;}
bool operator <(const L&y)const{return slop<y.slop;}
bool left(P y){return (v^(y-p))>eps;}
}q[MN+],s[MN+];
int n,top,tail; void solve()
{
q[top=tail=]=s[];
for(int i=;i<=n;i++)
{
while(top>tail&&!s[i].left(p[top])) --top;
while(top>tail&&!s[i].left(p[tail+])) ++tail;
if(fabs(s[i].slop-q[top].slop)<eps)
q[top]=s[i].left(q[top].p)?q[top]:s[i];
else
q[++top]=s[i];
p[top]=q[top]*q[top-];
}
while(top>tail&&!q[tail].left(p[top])) --top;
} int main()
{
n=read();
for(int i=;i<=n;i++)
{
double x,y,x2,y2;scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
s[i]=L(P(x,y),P(x2-x,y2-y));
}
s[++n]=L(P(,),P(,));
s[++n]=L(P(,),P(,));
s[++n]=L(P(,),P(-,));
s[++n]=L(P(,),P(,-));
sort(s+,s+n+);
solve();p[tail]=q[top]*q[tail];
if(top-tail<) return *puts("0.0");
ld ans=p[top]^p[tail];
for(int i=tail;i<top;i++) ans+=p[i]^p[i+];
printf("%.1lf\n",(double)fabs(ans)/2.0);
return ;
}
[poj2451]Uyuw's Concert的更多相关文章
- POJ2451 Uyuw's Concert (半平面交)
POJ2451 给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- 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 (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- Uyuw's Concert POJ2451
裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- poj 2451 Uyuw's Concert
[题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...
- 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 ...
随机推荐
- "未找到应用程序的“aps-environment”的权利字符串"
1.先生成App ID,在去Provisioning里面生成新的Profile 2.删除Xcode里面原来的push profile(如果没有就不用删除)再次双击新下载的profile(mobilep ...
- HTTP协议中PUT和POST使用区别
有的观点认为,应该用POST来创建一个资源,用PUT来更新一个资源:有的观点认为,应该用PUT来创建一个资源,用POST来更新一个资源:还有的观点认为可以用PUT和POST中任何一个来做创 ...
- 开始使用HTML5和CSS3验证表单
使用HTML5和CSS3验证表单 客户端验证是网页客户端程序最常用的功能之一,我们之前使用了各种各样的js库来进行表单的验证.HTML5其实早已为我们提供了表单验证的功能.至于为啥没有流行起来估计是兼 ...
- web信息泄露注意事项
1. 确保您的Web服务器不发送显示有关后端技术类型或版本信息的响应头. 2. 确保服务器打开的端口上运行的所有服务都不会显示有关其构建和版本的信息. 3. 确保所有目录的访问权限正确,保证不会让攻击 ...
- 使用 BenchmarkDotnet 测试代码性能
先来点题外话,清明节前把工作辞了(去 tm 的垃圾团队,各种拉帮结派.勾心斗角).这次找工作就得慢慢找了,不能急了,希望能找到个好团队,好岗位吧.顺便这段时间也算是比较闲,也能学习一下和填掉手上的坑. ...
- build.gradle & gradle.properties
一.build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { maven { cred ...
- 新概念英语(1-141)Sally's first train ride
Lesson 141 Sally's first train ride 萨莉第一交乘火车旅行 Listen to the tape then answer this question. Why was ...
- [机器学习Lesson3] 梯度下降算法
1. Gradient Descent(梯度下降) 梯度下降算法是很常用的算法,可以将代价函数J最小化.它不仅被用在线性回归上,也被广泛应用于机器学习领域中的众多领域. 1.1 线性回归问题应用 我们 ...
- spring mvc跨域(ajax post json)--filter方案
@RequestMapping(value = "/login.do",method = RequestMethod.POST) public Message login(Http ...
- Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!
Hibernate版本5.2.9 获取Session的方式是sessionFactory.getCurrentSession(); 比较老一些的版本使用的是sessionFactory.openSes ...