半平面交滴裸题,但是要求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的更多相关文章

  1. POJ2451 Uyuw's Concert (半平面交)

    POJ2451  给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...

  2. POJ2451 Uyuw's Concert(半平面交)

    题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...

  3. poj 2451 Uyuw's Concert(半平面交)

    Uyuw's Concert Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8580   Accepted: 3227 De ...

  4. poj 2451 Uyuw's Concert (半平面交)

    2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...

  5. Uyuw's Concert POJ2451

    裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...

  6. POJ 2451 Uyuw's Concert (半平面交)

    题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...

  7. poj 2451 Uyuw's Concert

    [题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...

  8. POJ 2451 Uyuw's Concert(半平面交nlgn)

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...

  9. bzoj 2451 Uyuw's Concert

    裸的半平面交.感觉这些东西,纯属在考代码能力啊.. #include<cstdio> #include<algorithm> #include<cmath> #de ...

随机推荐

  1. 【iOS】Swift类的继承、构造方法、析构器等复习

    一.继承与重写, 防止重写 1.1 基类, 不继承任何类. Swift不想OC或者Java中继承自Object类.定义一个类,不继承任何类,该类就是基类. [java] view plaincopy ...

  2. Vue filter介绍及详细使用

    Vue filter介绍及其使用 VueJs 提供了强大的过滤器API,能够对数据进行各种过滤处理,返回需要的结果. Vue.js自带了一些默认过滤器例如: capitalize 首字母大写 uppe ...

  3. 使用Google 的 gson方式解析json

    gson支持解析的类型还是比较全面的,包括JavaBean,List<JavaBean>,List<String>,Map等,使用起来也是比较方便,下面根据代码示例给出总结: ...

  4. 记一次SQL调优/优化(SQL tuning)——性能大幅提升千倍以上

    好久不写东西了,一直忙于各种杂事儿,恰巧昨天有个用户研发问到我一个SQL调优的问题,说性能太差,希望我能给调优下,最近有些懒,可能和最近太忙有关系,本来打算问问现在的情况,如果差不多就不调了,那哥们儿 ...

  5. python 中os.path.join 双斜杠的解决办法

    这两天在写东西的时候遇到了这个问题,主要是上传图片之后,无法在页面展示,原因就出在用join 拼接的路径中出现了"\"而造成的. >>> import os &g ...

  6. angluarjs2入门学习资源

    http://www.runoob.com/angularjs2/angularjs2-tutorial.htmlhttps://segmentfault.com/a/1190000008423981 ...

  7. linux下的Shell编程(7)使用-x和-n调试shell程序

    我们也可以在Shell下调试Shell Script脚本,当然最简单的方法就是用echo输出查看变量取值了.Bash也提供了真正的调试方法,就是执行脚本的时候用-x参数. sh -x filename ...

  8. Angular UI框架 Ng-alain @delon的脚手架的生成开发模板

    前言 首先感谢下 cipchk基于 Ng-Zorror 框架上制作的ng-alain . 之前很早就关注了 ng-alain,今天得空折腾了下. 折腾的时候发现官方文档有些坑,没有写清楚,所以我作为一 ...

  9. 详解Windows Server 2008 R2下安装Oracle 11g

    本篇文章转载 http://www.it165.net/database/html/201212/3385.html 一.安装前的准备工作: 1. 修改计算机名: 服务器的计算机名称对于登录到Orac ...

  10. tk mybatis通用mapper,复杂and or条件查询

    需求:where查询,需要支持(a or b or c) and d 也就是a.b.c三个条件是或的关系,然后再与d相与. 尝试后,可以通过以下方式处理: 方式1:Weekend语法 Weekend& ...