//三角剖分求多边形面积的交 HDU3060

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn = ;
const int maxisn = ;
const double eps = 1e-;
const double pi = acos(-1.0); int dcmp(double x) {
if(x > eps) return ;
return x < -eps ? - : ;
} struct Point {
double x, y;
Point() {
x = y = ;
}
Point(double a, double b) {
x = a, y = b;
}
inline Point operator-(const Point &b)const {
return Point(x - b.x, y - b.y);
}
inline Point operator+(const Point &b)const {
return Point(x + b.x, y + b.y);
}
inline double dot(const Point &b)const {
return x * b.x + y * b.y;
}
inline double cross(const Point &b, const Point &c)const {
return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);
}
}; Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d) {
double u = a.cross(b, c), v = b.cross(a, d);
return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v));
} double PolygonArea(Point p[], int n) {
if(n < ) return 0.0;
double s = p[].y * (p[n - ].x - p[].x);
p[n] = p[];
for(int i = ; i < n; ++ i)
s += p[i].y * (p[i - ].x - p[i + ].x);
return fabs(s * 0.5);
} double CPIA(Point a[], Point b[], int na, int nb) { //ConvexPolygonIntersectArea
Point p[maxisn], tmp[maxisn];
int i, j, tn, sflag, eflag;
a[na] = a[], b[nb] = b[];
memcpy(p, b, sizeof(Point) * (nb + ));
for(i = ; i < na && nb > ; ++ i) {
sflag = dcmp(a[i].cross(a[i + ], p[]));
for(j = tn = ; j < nb; ++ j, sflag = eflag) {
if(sflag >= ) tmp[tn ++] = p[j];
eflag = dcmp(a[i].cross(a[i + ], p[j + ]));
if((sflag ^ eflag) == -)
tmp[tn ++] = LineCross(a[i], a[i + ], p[j], p[j + ]);
}
memcpy(p, tmp, sizeof(Point) * tn);
nb = tn, p[nb] = p[];
}
if(nb < ) return 0.0;
return PolygonArea(p, nb);
} double SPIA(Point a[], Point b[], int na, int nb) { //SimplePolygonIntersectArea
int i, j;
Point t1[], t2[];
double res = , if_clock_t1, if_clock_t2;
a[na] = t1[] = a[], b[nb] = t2[] = b[];
for(i = ; i < na; ++ i) {
t1[] = a[i - ], t1[] = a[i];
if_clock_t1 = dcmp(t1[].cross(t1[], t1[]));
if(if_clock_t1 < ) std::swap(t1[], t1[]);
for(j = ; j < nb; ++ j) {
t2[] = b[j - ], t2[] = b[j];
if_clock_t2 = dcmp(t2[].cross(t2[], t2[]));
if(if_clock_t2 < ) std::swap(t2[], t2[]);
res += CPIA(t1, t2, , ) * if_clock_t1 * if_clock_t2;
}
}
return PolygonArea(a, na) + PolygonArea(b, nb) - res;
} Point p1[maxn], p2[maxn];
int n1, n2; int main() {
int i;
while(scanf("%d%d", &n1, &n2) != EOF) {
for(i = ; i < n1; ++ i) scanf("%lf%lf", &p1[i].x, &p1[i].y);
for(i = ; i < n2; ++ i) scanf("%lf%lf", &p2[i].x, &p2[i].y);
printf("%.2f\n", SPIA(p1, p2, n1, n2) + eps);
}
return ;
}

三角剖分求多边形面积的交 HDU3060的更多相关文章

  1. hdu1255 覆盖的面积 线段树+里离散化求矩形面积的交

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1 ...

  2. hdu 2036 求多边形面积 (凸、凹多边形)

    <题目链接> Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考 ...

  3. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. poj 1654:Area 区域 ---- 叉积(求多边形面积)

    Area   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19398   Accepted: 5311 利用叉积求多边形面 ...

  5. [poj] 3907 Build Your Home || 求多边形面积

    原题 多组数据,到0为止. 每次给出按顺序的n个点(可能逆时针,可能顺时针),求多边形面积(保留整数) 多边形面积为依次每条边(向量)叉积/2的和 \(S=\sum _{i=1}^{n-1}p[i]* ...

  6. HDU - 2036 改革春风吹满地 叉乘法求多边形面积

    改革春风吹满地 “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟 ...

  7. 使用Delaunay三角剖分解决求多边形面积的问题

    朋友那边最近有个需求,需要框选一个选区,然后根据选区中的点求出面积.并且让我尝试用Delaunay来解决 似乎音译过来应该是德诺类 大致如下: 我在github上找了一个可以用的Delaunay库 h ...

  8. Area - POJ 1654(求多边形面积)

    题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...

  9. poj 1654 Area(计算几何--叉积求多边形面积)

    一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...

随机推荐

  1. Iterator的remove方法可保证从源集合中安全地删除对象(转)

    如果对正在被迭代的集合进行结构上的改变(即对该集合使用add.remove或clear方法),那么迭代器就不再合法(并且在其后使用该迭代器将会有ConcurrentModificationExcept ...

  2. javascript 递归调用

    上源码:underscore.js var flatten = function(input, shallow, output) { if (shallow && _.every(in ...

  3. Difference between Pragma and Cache-control headers?

    Pragma is the HTTP/1.0 implementation and cache-control is the HTTP/1.1 implementation of the same c ...

  4. leetcode:Contains Duplicate和Contains Duplicate II

    一.Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your fun ...

  5. fix org.openqa.selenium.NoSuchWindowException when find element on windows8.1 ie11.

    Steps:1.I was able to resolve the issue after adding the site URL under trusted sites of IE. The sam ...

  6. 将js对象转为json对象属性加上引号

    工具地址 http://js2json.mengxiangchaoren.com

  7. toB的产品经理和toc产品经理区别

    腾讯产品经理现身说法 曾经在UC做过2年to c的app,现在在腾讯做to b的产品. 做to c产品的时候,我很瞧不起做to b产品的同学,认为他们不过是做支撑的. 后来,我参与了一个to b平台级 ...

  8. 【英语】Bingo口语笔记(1) - Hold

    how are you holding up? 你还撑得住吧?你还好吧?撑住太不容易了吧!

  9. android 语言切换过程分析

    android 语言切换过程分析 2014-02-27 18:13 1207人阅读 评论(0) 收藏 举报 语言切换android语言切换android改变语言 最近在看一个bug,系统切换语言后,本 ...

  10. LoopBar – Tap酒吧与无限滚动

    相约 LoopBar – 标签栏与无限滚动为Android由Cleveroad 在Cleveroad我们最近认识到通过使用任何一个应用程序类别的导航,导航面板是很无聊和琐碎.这就是为什么我们的设计师的 ...