半平面交滴裸题,但是要求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. 学习UI的总结

    学习前端有一段时间了,一直在看书上的理论知识,而实战项目却很少.老师常说,想要知道自己的实力有多少,知识掌握了多少,最好的方法就是去实践了,实践出真知嘛.于是在学习中,总要是通过项目的实践以及理论知识 ...

  2. vue 手机端开发 小商铺 添加购物车 以及结算 功能

    这个功能绕了我一天!!!            对 就是这个功能  一系列相关联的  四处相关联 现在加班 没时间更 过两天在更

  3. js 中bind

    function fn(a){ this.innerHTML = a; console.log(this); } //fn("hello"); span1.onclick =fun ...

  4. STM32读取温湿度传感器DHT11和DHT21(AM2301)系列问题

    1.DHT11和DHT21传感器 这两种传感器都是奥松公司的产品,具体的传感器说明书在其官网上有(www.aosong.com). DHT11 数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合 ...

  5. Python爬虫之urllib模块2

    Python爬虫之urllib模块2 本文来自网友投稿 作者:PG-55,一个待毕业待就业的二流大学生. 看了一下上一节的反馈,有些同学认为这个没什么意义,也有的同学觉得太简单,关于Beautiful ...

  6. angular2 学习笔记 ( angular cli & npm version manage npm 版本管理 )

    更新 : 2017-05-05 现在流行 Yarn ! 它是 facebook google 推出的东西. 算是补助 npm 做的不够好的地方. 源码依然是发布去 npm,只是下载接口换掉罢了哦. n ...

  7. docker实践3

    我的docker学习笔记3   $docker run ubuntu echo'hello world' $docker run -i -t ubuntu /bin/bash #ps -ef #exi ...

  8. [52ABP实战课程系列]Docker&Ubuntu从入门到实战开课啦~

    任何的课程都逃不开理论的支持 久等了各位,在Asp.NET Core2.0 项目实战入门视频课程结束后,根据发起的投票信息.Docker 排在首位.按照结果,我们开始进行Docker视频课程的录制. ...

  9. Mysql官方文档翻译系列14.18--MySql备份与恢复

    原文链接: (https://dev.mysql.com/doc/refman/5.7/en/innodb-backup-recovery.html) The key to safe database ...

  10. 项目实战15—企业级堡垒机 jumpserver

    本文收录在Linux运维企业架构实战系列 环境准备 系统:CentOS 7 IP:192.168.10.101 关闭selinux 和防火墙 # CentOS $ setenforce # 可以设置配 ...