//三角剖分求多边形面积的交 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. USACO Section 3.3: A Game

    第一次碰到博弈论题目,是很棘手,博弈论题目要考虑全局最优的解法,我第一次用了局部最优的,而且vector也没pop_front()操作.后来看了网上的用dp的方法解的. 博弈论的题目基本都得用dp法子 ...

  2. git 创建branch分支【转】

    转自:http://www.cnblogs.com/jackluo/p/3499731.html 开发者user1 负责用getopt 进行命令解析的功能,因为这个功能用到getopt 函数,于是将这 ...

  3. .net Windows服务程序和安装程序制作图解 及 VS 2010创建、安装、调试 windows服务(windows service)

    .net Windows服务程序和安装程序制作 最近项目中用到window服务程序,以前没接触过,比较陌生,花了两天的时间学习了下,写了个简单的服务,但在制作安装程序的时候,参照网上很多资料,却都制作 ...

  4. 深入理解Java内存模型(七)——总结

    处理器内存模型 顺序一致性内存模型是一个理论参考模型,JMM和处理器内存模型在设计时通常会把顺序一致性内存模型作为参照.JMM和处理器内存模型在设计时会对顺序一致性模型做一些放松,因为如果完全按照顺序 ...

  5. django中的filter和get的区别 (MultipleObjectsReturned: get() returned more than one Publisher --)(DoesNotExist: Publisher matching query does not exist.)

    上面的例子中`` filter()`` 函数返回一个记录集,这个记录集是一个列表. 相对列表来说,有些时候我们更需要获取单个的对象, `` get()`` 方法就是在此时使用的: >>&g ...

  6. centos 升级GCC/G++

    #get rep yum install centos-release-scl-rh #yum install centos-release-scl # install g++ 5.2.1 yum - ...

  7. zookeeper监控告警

    一.ZooKeeper简介 ZooKeeper作为分布式系统中重要的组件,目前在业界使用越来越广泛,ZooKeeper的使用场景非常多,以下是几种典型的应用场景: l  数据发布与订阅(配置中心) l ...

  8. 邦定lua函数到C里做为回调

    1,  int ref = luaL_ref(L, LUA_REGISTRYINDEX); //把栈顶的obj  存在lua的表里面,返回一个唯一的引用,(栈顶的obj被自动清除),,(这个引用作为回 ...

  9. Android开源库--Asynchronous Http Client异步http客户端

    如果说我比别人看得更远些,那是因为我站在了巨人的肩上. github地址:https://github.com/loopj/android-async-http Api文档地址:http://loop ...

  10. B/S 和 C/S

    B/S最大优势为客户端免维护,适用于用户群庞大,或客户需求经长发生变化的情况. C/S功能强大,可以减轻服务器端压力,如果用户的需求特别复杂,用C/S. 全面: Client/Server是建立在局域 ...