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

 #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. Android Studio的HAXM不支持虚拟机

    因为我的计算机是服务器,不支持虚拟机,所以报这个错了. 解决方式是直接连接物理手机,打开USB调试,安装驱动,运行项目即可.

  2. CSP-S 2019 初赛游记

    Day 0 上午考了一套毒瘤的数据结构题,考的我心态爆炸SB出题人 晚上考了一套初赛模拟,只考1h,然后我91分,感觉初赛完全没问题? 回寝室后一直在忙活,整理东西什么的,居然将近12点睡? Day ...

  3. tcpdump 获取SQL

    tcpdump [-aAdDefhIJKlLnNOpqRStuUvxX] [ -B size ] [ -c count ] [ -C file_size ] [ -E algo:secret ] [ ...

  4. Broadcast机制(二)

    内容提纲: 在本节课当中,我会继续为大家讲解Android的广播机制,重点内容有以下的两个方面: a)         在应用程序当中注册BroadcastReceiver的方法 b)         ...

  5. Android反编译与防止反编译

    1.Android反编译      1)下载两个工具  dex2jar,jar2java,相关阅读下载见:http://www.linuxidc.com/Linux/2011-02/32775.htm ...

  6. 面试题23从上到下打印二叉树+queue操作

    //本题思路就是层次遍历二叉树,使用一个队列来模拟过程 /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *ri ...

  7. ROS-3 : Catkin工作空间和ROS功能包

    一.创建一个Catkin工作空间 步骤一:构建catkin工作空间 安装完成ROS版本后,设置好环境变量:$ source /opt/ros/kinetic/setup.bash.然后即可创建一个ca ...

  8. 扩展新函数给window

    page.exposeFunction(name, puppeteerFunction) name <string> Name of the function on the window ...

  9. USACO[19-20]Dec银组题解

    1,MooBuzz 这题其实是道数学题. 我们先找找符合要求的数:1,2,4,7,8,11,13,14…… 我们发现再往后找都是这8个数中的一个加15k如:16……19……29…… 找规律发现k=n/ ...

  10. 蓝桥杯 能量项链 (区间dp)

    问题描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...