//三角剖分求多边形面积的交 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. Grunt :任务自动管理工具

    来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 在Javascript的开发过程中,经常会遇到一些重复性的任务,比如合并文件.压缩代码.检查语法错误.将Sass代码 ...

  2. emacs 快捷键笔记

    C-d C-aM-aC-eM-e===复制黏贴M-d    kill-wordM-del     backward-kill-wordM-k     kill-sentenceC-x del back ...

  3. android 设置控件的颜色,字体

    1.用代码设置控件的颜色:    int b =  getResources().getColor(R.drawable.blue);//得到配置文件里的颜色    mButton.setTextCo ...

  4. PL/SQL 如何导出INSERT语句

    需要把查询出来的数据导出成Insert的语句.忽然发现不会用了. 上网查,找到一些,但都不尽如人意. 于是就写了这篇文章.助人助己. 在PL/SQL Developer左边的树状导航栏里,找到[Tab ...

  5. 细说:Unicode, UTF-8, UTF-16, UTF-32, UCS-2, UCS-4

    1. Unicode与ISO 10646 全世界很多个国家都在为自己的文字编码,并且互不想通,不同的语言字符编码值相同却代表不同的符号(例如:韩文编码EUC-KR中“한국어”的编码值正好是汉字编码GB ...

  6. 【转】Android之内存泄漏调试学习与总结

    大家有或经常碰到OOM的问题,对吧?很多这样的问题只要一出现相信大家的想法跟小马的一样,就是自己的应用:优化.优化.再优化!而且如果出现类似于OOM这样级别的问题,根本就不好处理,LogCat日志中显 ...

  7. 《OD大数据实战》Hue环境搭建

    官网: http://archive.cloudera.com/cdh5/cdh/5/hue-3.7.0-cdh5.3.6/ 一.Hue环境搭建 1. 下载 http://archive.cloude ...

  8. jboss jndi配置部分参数详解

    使用的是jboss7.1.1, jndi的配置在$JBOSS_HOME/standalone/configuration/standalone.xml中进行配置.配置jndi时有很多参数,解释下用到的 ...

  9. java中进程与线程的三种实现方式

    一:进程与线程 概述:几乎任何的操作系统都支持运行多个任务,通常一个任务就是一个程序,而一个程序就是一个进程.当一个进程运行时,内部可能包括多个顺序执行流,每个顺序执行流就是一个线程. 进程:进程是指 ...

  10. bzoj2982: combination

    借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法 #include<cstdio> #include<cstring> #include<cctype&g ...