据说pkusc出了好几年半平面交了,我也来水一发

ref

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, cnt, tot;
const double eps=1e-7;
struct Point{
double x, y;
Point(double u=0.0, double v=0.0){
x = u; y = v;
}
Point operator+(const Point &u)const{
return Point(x+u.x, y+u.y);
}
Point operator-(const Point &u)const{
return Point(x-u.x, y-u.y);
}
double crs(Point u){
return x*u.y-y*u.x;
}
}pt[55], a[1005];
struct Line{
Point x, y;
double ang;
Line(){}
Line(Point u, Point v){
x = u; y = v;
ang = atan2(v.y-u.y, v.x-u.x);
}
}l[1005], d[1005];
Point operator*(double x, Point u){
return Point(x*u.x, x*u.y);
}
bool cmp(Line u, Line v){
if(fabs(u.ang-v.ang)>=eps) return u.ang<v.ang;
return (u.y-u.x).crs(v.y-u.x)>eps;
}
Point inter(Line u, Line v){
double t=(v.x-u.x).crs(v.y-u.x)/((v.x-u.x).crs(v.y-u.x)+(v.y-u.y).crs(v.x-u.y));
return u.x+t*(u.y-u.x);
}
bool isLeft(Point u, Line v){
return (v.y-v.x).crs(u-v.x)>eps;
}
void halfPlaneIntersection(){
sort(l+1, l+1+cnt, cmp);
for(int i=1; i<=cnt; i++){
if(i==1 || fabs(l[i].ang-l[i-1].ang)>=eps) tot++;
l[tot] = l[i];
}
cnt = tot; tot = 0;
int ll=1, rr=0;
d[++rr] = l[1]; d[++rr] = l[2];
for(int i=3; i<=cnt; i++){
while(ll<rr && !isLeft(inter(d[rr-1], d[rr]), l[i])) rr--;
while(ll<rr && !isLeft(inter(d[ll+1], d[ll]), l[i])) ll++;
d[++rr] = l[i];
}
while(ll<rr && !isLeft(inter(d[rr-1], d[rr]), d[ll])) rr--;
while(ll<rr && !isLeft(inter(d[ll+1], d[ll]), d[rr])) ll++;
d[rr+1] = d[ll];
for(int i=ll; i<=rr; i++)
a[++tot] = inter(d[i], d[i+1]);
}
double ans(){
if(tot<3) return 0.0;
a[tot+1] = a[1];
double re=0;
for(int i=1; i<=tot; i++)
re += a[i].crs(a[i+1]);
return re/2;
}
int main(){
cin>>n;
while(n--){
int mi;
scanf("%d", &mi);
for(int i=1; i<=mi; i++)
scanf("%lf %lf", &pt[i].x, &pt[i].y);
pt[mi+1] = pt[1];
for(int i=1; i<=mi; i++)
l[++cnt] = (Line){pt[i], pt[i+1]};
}
halfPlaneIntersection();
printf("%.3f\n", ans());
return 0;
}

luogu4196 [CQOI2006]凸多边形 半平面交的更多相关文章

  1. BZOJ2618[Cqoi2006]凸多边形——半平面交

    题目描述 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. 输入 第一行有一个整数n,表示凸多边形的个数,以下依次描述各个多边形.第 ...

  2. 【bzoj2618】[Cqoi2006]凸多边形 半平面交

    题目描述 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. 输入 第一行有一个整数n,表示凸多边形的个数,以下依次描述各个多边形.第 ...

  3. bzoj2618[Cqoi2006]凸多边形 半平面交

    这是一道半平面交的裸题,第一次写半平面交,就说一说我对半平面交的理解吧. 所谓半平面交,就是求一大堆二元一次不等式的交集,而每个二元一次不等式的解集都可以看成是在一条直线的上方或下方,联系直线的标准方 ...

  4. P4196 [CQOI2006]凸多边形 半平面交

    \(\color{#0066ff}{题目描述}\) 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. \(\color{#0066f ...

  5. POJ3525 半平面交

    题意:求某凸多边形内部离边界最远的点到边界的距离 首先介绍半平面.半平面交的概念: 半平面:对于一条有向直线,它的方向的左手侧就是它所划定的半平面范围.如图所示: 半平面交:多个半平面的交集.有点类似 ...

  6. bzoj 4445 小凸想跑步 - 半平面交

    题目传送门 vjudge的快速通道 bzoj的快速通道 题目大意 问在一个凸多边形内找一个点,连接这个点和所有顶点,使得与0号顶点,1号顶点构成的三角形是最小的概率. 假设点的位置是$(x, y)$, ...

  7. 【kuangbin专题】计算几何_半平面交

    1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...

  8. bzoj 3190 赛车 半平面交

    直接写的裸的半平面交,已经有点背不过模板了... 这题卡精度,要用long double ,esp设1e-20... #include<iostream> #include<cstd ...

  9. BZOJ 4445 [Scoi2015]小凸想跑步:半平面交

    传送门 题意 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 $ n $ 边形,$ n $ 个顶点 $ P_i $ 按照逆时针从 $ 0 $ 至 $ n-1 $ 编号. ...

随机推荐

  1. *1 Two Sum two pointers(hashmap one scan)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  2. 377. Combination Sum IV 70. Climbing Stairs

    back function (return number) remember the structure class Solution { int res = 0; //List<List< ...

  3. hdu-2688 Rotate---树状数组+模拟

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2688 题目大意: 给你n数,(n<=3e6),有两个操作,Q为 当前有多少对数,满足严格递增, ...

  4. A. Kyoya and Colored Balls_排列组合,组合数

    Codeforces Round #309 (Div. 1) A. Kyoya and Colored Balls time limit per test 2 seconds memory limit ...

  5. python中的for循环如何控制步长

    for i in range(开始/左边界, 结束/右边界, 步长): print i 例如 for i in range(1, 10, 2): print i 等价于 for (i=1;i<= ...

  6. Vuex基础-State

    官方地址:https://vuex.vuejs.org/zh/guide/state.html 由于 Vuex 的状态存储是响应式的,从 store 实例中读取状态最简单的方法就是在计算属性中返回某个 ...

  7. SQL按时间段统计(5分钟统计一次访问量为例,oracle统计)

    需求:统计当天的访问量,每五分钟采集一次 表结构中有日期字段,类型TIMESTAMP 如果,统计是采用每秒/分钟/小时/天/周/月/年,都非常容易实现,只要to_char日期字段然后group by分 ...

  8. javascript入门笔记6-内置对象

    1.Date 日期对象 日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 定义一个时间对象 : var Udate=new Date(); 注意:使用关键字new,Date() ...

  9. SpringBoot学习5:访问静态资源

    springboot默认从项目的resources里面的static目录下或者webapp目录下访问静态资源 方式一:在resources下新建static文件(文件名必须是static) 在浏览器中 ...

  10. python数据类型的转换