2018.07.04 BZOJ 2618 Cqoi2006凸多边形(半平面交)
2618: [Cqoi2006]凸多边形
Time Limit: 5 Sec Memory Limit: 128 MB
Description
逆时针给出n个凸多边形的顶点坐标,求它们交的面积。例如n=2时,两个凸多边形如下图:
则相交部分的面积为5.233。
Input
第一行有一个整数n,表示凸多边形的个数,以下依次描述各个多边形。第i个多边形的第一行包含一个整数mi,表示多边形的边数,以下mi行每行两个整数,逆时针给出各个顶点的坐标。
Output
输出文件仅包含一个实数,表示相交部分的面积,保留三位小数。
Sample Input
2
6
-2 0
-1 -2
1 -2
2 0
1 2
-1 2
4
0 -3
1 -1
2 2
-1 0
Sample Output
5.233
HINT
100%的数据满足:2<=n<=10,3<=mi<=50,每维坐标为[-1000,1000]内的整数
这是一道半平面交模板题,实际上,这道题将半平面交的裸板题中的一个多边形拆成了多个多边形,这样的话只需要在输入时调整一下就可以套上板子了(然而本蒟蒻调输入调了30min+" role="presentation" style="position: relative;">30min+30min+),代码实现上也没有什么太多的细节,简单用双端队列维护一下就行了。
代码如下:
#include<bits/stdc++.h>
#define N 1005
#define eps 1.0e-12
using namespace std;
struct point{double x,y;}p[N];
struct line{
point a,b;
double poa;
}l[N];
int n,m,tot,head=0,tail=0,q[N],siz=0;
inline point operator-(point a,point b){return point{a.x-b.x,a.y-b.y};}
inline double cross(point a,point b){return a.x*b.y-a.y*b.x;}
inline point across(line a,line b){
double a1=cross(b.b-a.a,b.a-a.a),a2=cross(b.a-a.b,b.b-a.b);
return point{(a2*a.a.x+a1*a.b.x)/(a2+a1),(a2*a.a.y+a1*a.b.y)/(a2+a1)};
}
inline bool check(point a,line b){return cross(a-b.a,b.b-b.a)>0;}
inline bool cmp(line a,line b){
if(fabs(a.poa-b.poa)<eps)return cross(a.b-b.a,b.b-b.a)<0;
return a.poa<b.poa;
}
inline double solve(){
sort(l+1,l+tot+1,cmp);
for(int i=1;i<=tot;++i)if(fabs(l[i-1].poa-l[i].poa)>eps)++siz,l[siz]=l[i];
q[1]=head=tail=1;
for(int i=2;i<=siz;++i){
while(head<tail&&check(across(l[q[tail-1]],l[q[tail]]),l[i]))--tail;
while(head<tail&&check(across(l[q[head]],l[q[head+1]]),l[i]))++head;
q[++tail]=i;
}
while(head<tail&&check(across(l[q[tail-1]],l[q[tail]]),l[q[head]]))--tail;
while(head<tail&&check(across(l[q[head]],l[q[head+1]]),l[q[tail]]))++head;
if(tail-head<=1)return 0.000;
for(int i=head;i<tail;++i)p[i-head+1]=across(l[q[i]],l[q[i+1]]);
p[tail-head+1]=across(l[q[tail]],l[q[head]]);
double ans=0.0000;
for(int i=1;i<=tail-head;++i)ans+=cross(p[i],p[i+1]);
ans+=cross(p[tail-head+1],p[1]);
return ans/2.0;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&m);
for(int j=1;j<=m;++j)scanf("%lf%lf",&p[j].x,&p[j].y);
p[m+1]=p[1];
for(int j=1;j<=m;++j)++tot,l[tot].a=p[j],l[tot].b=p[j+1];
}
for(int i=1;i<=tot;++i)l[i].poa=atan2(l[i].b.y-l[i].a.y,l[i].b.x-l[i].a.x);
printf("%.3lf",solve());
return 0;
}
2018.07.04 BZOJ 2618 Cqoi2006凸多边形(半平面交)的更多相关文章
- bzoj 2618: [Cqoi2006]凸多边形 [半平面交]
2618: [Cqoi2006]凸多边形 半平面交 注意一开始多边形边界不要太大... #include <iostream> #include <cstdio> #inclu ...
- 洛谷 P4196 [CQOI2006]凸多边形 (半平面交)
题目链接:P4196 [CQOI2006]凸多边形 题意 给定 \(n\) 个凸多边形,求它们相交的面积. 思路 半平面交 半平面交的模板题. 代码 #include <bits/stdc++. ...
- 2018.07.03 POJ 1279Art Gallery(半平面交)
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...
- ●BZOJ 2618 [Cqoi2006]凸多边形
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2618 题解: 计算几何,半平面交. 给出一些凸包,求面积交. 把所有边都取出来,直接办平面交 ...
- 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)
2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- bzoj 2618 2618: [Cqoi2006]凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 656 Solved: 340[Submit][Status] ...
- BZOJ - 2618 凸多边形 (半平面交)
题意:求n个凸多边形的交面积. 半平面交模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; ty ...
- 2018.07.03 BZOJ 1007: [HNOI2008]水平可见直线(简单计算几何)
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB Description 在xoy直角坐标平面上有n条直线L1,L2,-Ln, ...
随机推荐
- c++builder Delphi 直接使用剪贴板 Clipboard
c++builder Delphi 直接使用剪贴板 Clipboard 剪贴板 delphi use Vcl.Clipbrd procedure TForm27.FormCreate(Sender: ...
- js倒计时发送验证码按钮
var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value=&q ...
- fb bin_debug下的swf不见了
fb清理了所选的项目,如果代码有错误,会自动删除bin_debug目录下的swf.这种情况,构建项目是无法自动生成swf的,只有将代码报错的地方修改正错了.选构建项目才会在bin_debug目录下生成 ...
- 前端-CSS-5-继承性&层叠性&权重比较
1.继承性 <style type="text/css"> .father{ font-size: 30px; background-color: green; } . ...
- c++ static成员
static 成员通常不能在类的定义体重初始化 有一种例外,const static成员可以在定义体内初始化,并且可以用于构造函数 将函数声明为const表示该函数不能修改其所属的对象
- tensorflow笔记之滑动平均模型
tensorflow使用tf.train.ExponentialMovingAverage实现滑动平均模型,在使用随机梯度下降方法训练神经网络时候,使用这个模型可以增强模型的鲁棒性(robust),可 ...
- Mysql日期时间Extract函数介绍
MySQL日期时间Extract函数的优点在于可以选取日期时间的各个部分,从年一直到微秒,让我们对MySQL日期时间的处理更为轻松. MySQL 日期时间 Extract(选取)函数.1. 选取日期时 ...
- jemalloc for mysql
ptmalloc 是glibc的内存分配管理 tcmalloc 是google的内存分配管理模块 jemalloc 是BSD的提供的内存分配管理 三者jemalloc和tcmalloc的性能不分伯仲, ...
- taskset: 让进程运行在指定的CPU 上
观察发现4核CPU,只有第1个核心(CPU#0)非常忙,其他都处于idle状态. 不了解Linux是如何调度的,但目前显然有优化的余地.除了处理正常任务,CPU#0还需要处理每秒网卡中断.因此,若能将 ...
- 通过yumdownloader下载rpm包
通过yum自带的一个工具:yumdownloader [root@web1 ~]# rpm -qa |grep yum-utils [root@web1 ~]# yum -y install yum ...