裸的半平面交。感觉这些东西,纯属在考代码能力啊。。

 #include<cstdio>
#include<algorithm>
#include<cmath>
#define eps 1e-8
using namespace std;
int n,tot;
double ans;
struct point{double x,y;}a[];
struct line{point a,b; double angle;}l[],q[];
point operator - (point a, point b){
point t; t.x=a.x-b.x; t.y=a.y-b.y; return t;
}
long double operator * (point a, point b){
return a.x*b.y-a.y*b.x;
}
bool operator < (line a, line b){
if (a.angle==b.angle) return (b.b-a.a)*(b.a-a.a)<;
return a.angle<b.angle;
}
point intersection_point(line a, line b)
{
double k1,k2,t;
point ans;
k1=(a.b-b.a)*(b.b-b.a);
k2=(b.b-b.a)*(a.a-b.a);
t=k1/(k1+k2);
ans.x=a.b.x+(a.a.x-a.b.x)*t;
ans.y=a.b.y+(a.a.y-a.b.y)*t;
return ans;
}
bool judge(line a, line b, line t)
{
point p=intersection_point(a,b);
// printf("%lf %lf\n",a.b.x,a.b.y);
return (t.a-p)*(t.b-p)<;
}
void half_plane_intersection()
{
sort(l+,l+n+);
int top=,bottom=; tot=;
for (int i=; i<=n; i++)
if (l[i].angle!=l[i-].angle) l[++tot]=l[i];
n=tot; q[]=l[]; q[]=l[];
//for (int i=1; i<=n; i++)
// printf("%.1lf %.1lf %.1lf %.1lf\n",l[i].a.x,l[i].a.y,l[i].b.x,l[i].b.y);
for (int i=; i<=n; i++)
{
while (bottom<top && judge(q[top],q[top-],l[i])) top--;
while (bottom<top && judge(q[bottom],q[bottom+],l[i])) bottom++;
q[++top]=l[i];
}
while (bottom<top && judge(q[top],q[top-],q[bottom])) top--;
while (bottom<top && judge(q[bottom],q[bottom+],q[top])) bottom++;
q[top+]=q[bottom];
tot=;
for (int i=bottom; i<=top; i++)
a[++tot]=intersection_point(q[i],q[i+]);
}
void get_area()
{
if (tot<) return;
a[++tot]=a[];
//for (int i=1; i<=tot; i++)
// printf("%lf %lf\n",a[i].x,a[i].y); while (1);
for (int i=; i<=tot; i++)
ans+=a[i]*a[i+];
ans=fabs(ans)/;
}
int main()
{
while (~scanf("%d",&n))
{
for (int i=; i<=n; i++)
scanf("%lf%lf%lf%lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y);
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
for (int i=; i<=n; i++)
l[i].angle=atan2((l[i].b.y-l[i].a.y),(l[i].b.x-l[i].a.x));
half_plane_intersection();
ans=; get_area();
printf("%.1lf",ans);
}
return ;
}

bzoj 2451 Uyuw's Concert的更多相关文章

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

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

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

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

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

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

  4. poj 2451 Uyuw's Concert

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

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

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

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

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

  7. Uyuw's Concert POJ2451

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

  8. [poj2451]Uyuw's Concert

    半平面交滴裸题,但是要求nlogn,练练手 #include<iostream> #include<cstdio> #include<cmath> #include ...

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

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

随机推荐

  1. 单元测试报错:unable to find a @SpringBootConfiguration

    完整异常: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBoo ...

  2. 设计模式课程 设计模式精讲 14-2 组合模式coding

    1 代码演练 1.1 代码演练1(组合模式1) 1.2 代码演练2(组合模式1之完善) 1 代码演练 1.1 代码演练1(组合模式1) 需求: 打印出木木网的课程结构, 我们用一个组建类作为接口,课程 ...

  3. apache服务器本质上说是一个TCP socket服务

    apache服务器本质上说是一个TCP socket服务,socket模型如下:  下面以worker MPM来说明apache代码中相应处理的位置在哪里: (以apache httpd 2.2.23 ...

  4. PHP pclzip.php 解压中文乱码

    修改 pclzip中方法privExtractFile 代码 if ($p_path != '') { $p_entry['filename'] = $p_path."/".$p_ ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:悬停表格

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. java程序中的经常出现的的异常处理课后总结

    一.JDK中常见的异常情况 1.常见异常总结图 2.java中异常分类 Throwable类有两个直接子类: (1)Exception:出现的问题是可以被捕获的 (2)Error:系统错误,通常由JV ...

  7. Spring之byte[]传输

    事出原因 某些原因,需要在在服务之间传输文件,想到只有通过Byte数组,或者是Stream传递,遂定下两方法,一个byte,一个inpustream,老样子,upload(@RequestParam( ...

  8. Zookeeper集群搭建(单机多节点,伪集群,docker-compose集群)

    Zookeeper介绍 原理简介 ZooKeeper是一个分布式的.开源的分布式应用程序协调服务.它公开了一组简单的原语,分布式应用程序可以在此基础上实现更高级别的同步.配置维护.组和命名服务.它的设 ...

  9. 2. 引用计数法(Reference Counting)

    1960年,George E. Collins 在论文中发布了引用计数的GC算法. 引用计数法意如了一个概念,那就是"计数器",计数器表示的是对象的人气指数, 也就是有多少程序引用 ...

  10. express写的接口在疯狂刷新几十次后,服务器挂掉

    用到的命令行: show status like 'Threads%'; show variables like '%max_connections%'; show global status lik ...