半平面交滴裸题,但是要求nlogn,练练手

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<algorithm>
  5. #define MN 50000
  6. #define eps 1e-17
  7. #define ld long double
  8. using namespace std;
  9. inline int read()
  10. {
  11. int x = , f = ; char ch = getchar();
  12. while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
  13. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  14. return x * f;
  15. }
  16.  
  17. struct P
  18. {
  19. ld x,y;
  20. P(ld _x=,ld _y=):x(_x),y(_y){}
  21. P operator +(P b){return P(x+b.x,y+b.y);}
  22. P operator -(P b){return P(x-b.x,y-b.y);}
  23. P operator *(ld b){return P(x*b,y*b);}
  24. ld operator^(P b){return x*b.y-b.x*y;}
  25. }p[MN+];
  26. struct L
  27. {
  28. P p,v;ld slop;
  29. L(){}
  30. L(P x,P y):p(x),v(y){slop=atan2(y.y,y.x);}
  31. P operator *(L y){P b=p-y.p;ld t=(y.v^b)/(v^y.v);return p+v*t;}
  32. bool operator <(const L&y)const{return slop<y.slop;}
  33. bool left(P y){return (v^(y-p))>eps;}
  34. }q[MN+],s[MN+];
  35. int n,top,tail;
  36.  
  37. void solve()
  38. {
  39. q[top=tail=]=s[];
  40. for(int i=;i<=n;i++)
  41. {
  42. while(top>tail&&!s[i].left(p[top])) --top;
  43. while(top>tail&&!s[i].left(p[tail+])) ++tail;
  44. if(fabs(s[i].slop-q[top].slop)<eps)
  45. q[top]=s[i].left(q[top].p)?q[top]:s[i];
  46. else
  47. q[++top]=s[i];
  48. p[top]=q[top]*q[top-];
  49. }
  50. while(top>tail&&!q[tail].left(p[top])) --top;
  51. }
  52.  
  53. int main()
  54. {
  55. n=read();
  56. for(int i=;i<=n;i++)
  57. {
  58. double x,y,x2,y2;scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
  59. s[i]=L(P(x,y),P(x2-x,y2-y));
  60. }
  61. s[++n]=L(P(,),P(,));
  62. s[++n]=L(P(,),P(,));
  63. s[++n]=L(P(,),P(-,));
  64. s[++n]=L(P(,),P(,-));
  65. sort(s+,s+n+);
  66. solve();p[tail]=q[top]*q[tail];
  67. if(top-tail<) return *puts("0.0");
  68. ld ans=p[top]^p[tail];
  69. for(int i=tail;i<top;i++) ans+=p[i]^p[i+];
  70. printf("%.1lf\n",(double)fabs(ans)/2.0);
  71. return ;
  72. }

[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. Flask 文件和流

    当我们要往客户端发送大量的数据比较好的方式是使用流,通过流的方式来将响应内容发送给客户端,实现文件的上传功能,以及如何获取上传后的文件. 响应流的生成 Flask响应流的实现原理就是通过Python的 ...

  2. Autowired注解

    package com.how2java.pojo; import org.springframework.beans.factory.annotation.Autowired; public cla ...

  3. 服务器数据恢复_Linux网站服务器故障数据恢复案例

    [数据恢复故障描述] 一台linux网站服务器,DELL R200,管理约50个左右网站,使用一块SATA 160GB硬盘.正常使用中突然宕机,尝试再次启动失败,将硬盘拆下检测时发现存在约100个坏扇 ...

  4. java希尔排序

    java希尔排序 1.基本思想: 希尔排序也成为"缩小增量排序",其基本原理是,现将待排序的数组元素分成多个子序列,使得每个子序列的元素个数相对较少,然后对各个子序列分别进行直接插 ...

  5. LeetCode & Q217-Contains Duplicate-Easy

    Array Hash Table Description: Given an array of integers, find if the array contains any duplicates. ...

  6. Mock API是如何在开发中发光发热的?

    在长期的服务过程中,我们经常会遇到前来咨询的用户与我们反馈以下这种情况:咨询者是一个前端人员,在项目开发的过程中需要与后端进行对接,遇到后端还没完成数据输出的情况下,他只好写静态模拟数据,在遇到大型项 ...

  7. 阿里云API网关(5)用户指南(调用 API)

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  8. 译《Time, Clocks, and the Ordering of Events in a Distributed System》

    Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...

  9. python Http协议

    Http协议 一 HTTP概述 HTTP(hypertext transport protocol),即超文本传输协议.这个协议详细规定了浏览器和万维网服务器之间互相通信的规则. HTTP就是一个通信 ...

  10. oracle12c:通过oracle客户端工具配置tns,并使用sqlldr进行批量导入数据

    通过oracle客户端工具配置tns: 进入oracle配置工具“Net Configuration Assistant”-> 点击“下一步”,完成tns配置. 测试是否tns可用 命令:tns ...