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

 #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. 「Luogu4556」Vani有约会-雨天的尾巴

    「Luogu4556」Vani有约会-雨天的尾巴 传送门 很显然可以考虑树上差分+桶,每次更新一条链就是把这条链上的点在桶对应位置打上 \(1\) 的标记, 最后对每个点取桶中非零值的位置作为答案即可 ...

  2. 「SP11470」TTM - To the moon

    题目描述 给定一段长度为 \(N\) 的序列 \(a\) 以及 \(M\) 次操作,操作有以下几种: C l r d :将区间 \([l,r]\) 中的数都加上 \(d\) Q l r :查询当前时间 ...

  3. [Write-up]-pwnlab_init

    关于 下载地址点我 Flag: /root/flag.txt 放假的第一天 哔哩哔哩视频 信息收集 nmap -sn 192.168.7.1/24 Starting Nmap 7.01 ( https ...

  4. 吴裕雄--天生自然HADOOP操作实验学习笔记:pvuv统计案例理论

    实验目的 复习pv.uv的概念和原理 了解pv.uv的实际意义和获取方法 实验原理 前面我们已经基于mapreduce进行数据的etl处理,实验有很多不足之处,这次实验我们是基于url数据进行pv和u ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:强制元素隐藏

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

  6. 为安卓手机刷上手机kali系统Nethunter

    kali Nethunter是一个装在手机上的kali,集成了kali的工具包,hid,无线攻击等等. 本文主要叙述如何安装此系统并正确的配置.不让你走弯路. 首先我们拒绝傻瓜安装软件 kali ne ...

  7. Android中的Sqlite中的onCreate方法和onUpgrade方法的执行时机--(转)

    原文:http://blog.csdn.net/jiangwei0910410003/article/details/46536329 今天在做数据库升级的时候,遇到一个问题,就是onCreate方法 ...

  8. Python3中找不到xrange定义和不能用len(map())

    问题1:python3中找不到xrange的定义,vscode中提示未定义 解决:改成range,因为python3中取消了vscode 问题2:python3中map函数返回的是迭代器,因此无法用l ...

  9. boost::timer demo

    #include <iostream> #include <boost/timer.hpp> //timer的头文件 using namespace boost; //打开bo ...

  10. Raspbian设置静态ip

    Raspbian static ip 最近入手了树莓派4b,并更具官方教程安装了Raspbian.由于直接通过wifi连接,每次ip跳来跳去很不方便,于是便想着设置静态ip. 由于Raspbian本身 ...