[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 ...
随机推荐
- Flask 文件和流
当我们要往客户端发送大量的数据比较好的方式是使用流,通过流的方式来将响应内容发送给客户端,实现文件的上传功能,以及如何获取上传后的文件. 响应流的生成 Flask响应流的实现原理就是通过Python的 ...
- Autowired注解
package com.how2java.pojo; import org.springframework.beans.factory.annotation.Autowired; public cla ...
- 服务器数据恢复_Linux网站服务器故障数据恢复案例
[数据恢复故障描述] 一台linux网站服务器,DELL R200,管理约50个左右网站,使用一块SATA 160GB硬盘.正常使用中突然宕机,尝试再次启动失败,将硬盘拆下检测时发现存在约100个坏扇 ...
- java希尔排序
java希尔排序 1.基本思想: 希尔排序也成为"缩小增量排序",其基本原理是,现将待排序的数组元素分成多个子序列,使得每个子序列的元素个数相对较少,然后对各个子序列分别进行直接插 ...
- LeetCode & Q217-Contains Duplicate-Easy
Array Hash Table Description: Given an array of integers, find if the array contains any duplicates. ...
- Mock API是如何在开发中发光发热的?
在长期的服务过程中,我们经常会遇到前来咨询的用户与我们反馈以下这种情况:咨询者是一个前端人员,在项目开发的过程中需要与后端进行对接,遇到后端还没完成数据输出的情况下,他只好写静态模拟数据,在遇到大型项 ...
- 阿里云API网关(5)用户指南(调用 API)
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- 译《Time, Clocks, and the Ordering of Events in a Distributed System》
Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...
- python Http协议
Http协议 一 HTTP概述 HTTP(hypertext transport protocol),即超文本传输协议.这个协议详细规定了浏览器和万维网服务器之间互相通信的规则. HTTP就是一个通信 ...
- oracle12c:通过oracle客户端工具配置tns,并使用sqlldr进行批量导入数据
通过oracle客户端工具配置tns: 进入oracle配置工具“Net Configuration Assistant”-> 点击“下一步”,完成tns配置. 测试是否tns可用 命令:tns ...