半平面交滴裸题,但是要求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 = 0 , f = 1; char ch = getchar();while(ch < '0' || ch > '9'){ if(ch == '-') f = -1;  ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;
}struct P
{ld x,y;P(ld _x=0,ld _y=0):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+5];
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+5],s[MN+5];
int n,top,tail;void solve()
{q[top=tail=1]=s[1];for(int i=2;i<=n;i++){while(top>tail&&!s[i].left(p[top])) --top;while(top>tail&&!s[i].left(p[tail+1])) ++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-1];}while(top>tail&&!q[tail].left(p[top])) --top;
}int main()
{n=read();for(int i=1;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(0,0),P(10000,0));s[++n]=L(P(10000,0),P(0,10000));s[++n]=L(P(10000,10000),P(-10000,0));s[++n]=L(P(0,10000),P(0,-10000));sort(s+1,s+n+1);solve();p[tail]=q[top]*q[tail];if(top-tail<2) return 0*puts("0.0"); ld ans=p[top]^p[tail];for(int i=tail;i<top;i++) ans+=p[i]^p[i+1];printf("%.1lf\n",(double)fabs(ans)/2.0);return 0;
}

转载于:https://www.cnblogs.com/FallDream/p/poj2451.html

[poj2451]Uyuw's Concert相关推荐

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

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

  2. 【计算几何】计算几何复习

    点,线,面,形基本关系,点积叉积的理解 poj2318 TOYS /****************************\* @prob: poj2318 TOYS ** @auth: Wang ...

  3. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  4. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  5. POJ 计算几何入门题目推荐

      其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专 ...

  6. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  7. 半平面交练习(计算几何)

    四:半平面交 Rotating Scoreboard /*Author : lifehappy */ #include <cstdio> #include <cmath> #i ...

  8. 计算几何相关资料+题目推荐(不定期补充)

    旋转卡壳:http://blog.csdn.net/accry/article/details/6070626 计算几何题目推荐:http://blog.csdn.net/accry/article/ ...

  9. [Z]POJ 计算几何入门题目推荐[转PKKJ]

    http://www.cnblogs.com/eric-blog/archive/2011/05/31/2064785.html http://hi.baidu.com/novosbirsk/blog ...

最新文章

  1. JAVA设计模式之门面模式(外观模式)
  2. Linux上程序调试的基石(2)--GDB
  3. vue-cli3中的vue.config.js配置
  4. 【HDU - 5916】Harmonic Value Description (构造,思维,SJ题)
  5. 如何计算页面打开获取流量_网站SEO优化如何获取更多的流量?
  6. php 自动选择时间的代码,JavaScript_extjs 时间范围选择自动判断的实现代码,extjs中 有时需要选择一个日期 - phpStudy...
  7. Auslogics Registry Cleaner v9.2.0.0 注册表清理优化工具
  8. 博弈论基础-蒋文华(浙大)
  9. 单设施选址-重心法-Matlab
  10. 互补品的需求曲线图_供给曲线和需求曲线的解析
  11. python中xlrd模块_Python中的xlrd模块使用原理解析
  12. [禅悟人生]心不动才能真正认清自己
  13. AI绘画火了!一文看懂背后技术原理
  14. java+jsp基于ssm的智慧医疗系统医院挂号就诊系统-计算机毕业设计
  15. python数组从小到大排序_Python 实现将数组值按从小到大的顺序排列
  16. JavaWeb黑马旅游网-学习笔记07【旅游线路查询】
  17. java 行政区划获取代码 省/市/县/乡镇/街道/村委会 层级 DivisionAdvUtil 爬虫获取完整的行政区划 代码完整 可运行
  18. HEAD: HEtero-Assists Distillation for Heterogeneous Object Detectors
  19. 人事面试100问(2)
  20. iOS - Shell 脚本学习入门

热门文章

  1. pycharm TabError: inconsistent use of tabs and spaces in indentation
  2. batch downloading file in python
  3. bar图设置距离 python_Python可视化分析:学会Matplotlib这几点就够了
  4. python中素数的求法_Python 2种方法求某个范围内的所有素数(质数)
  5. java word2007_Java解析word2007、Excel2003和Excel2007
  6. HowNet介绍及使用
  7. animation 循环_汽车前照灯与前雾灯热循环试验
  8. React学习笔记一 JSX语法组件
  9. Linux内核移植漫谈——你不是第一个想移植Linux内核的人
  10. android webview的一些设置问题