题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1632
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Given two convex polygons, they may or may not overlap. If they do overlap, they will do so to differing degrees and in different ways. Write a program that will read in the coordinates of the corners of two convex polygons and calculate the `exclusive or' of the two areas, that is the area that is bounded by exactly one of the polygons. The desired area is shaded in the following diagram:

Input

Input will consist of pairs of lines each containing the number of vertices of the polygon, followed by that many pairs of integers representing the x,y coordinates of the corners in a clockwise direction. All the coordinates will be positive integers less than 100. For each pair of polygons (pair of lines in the data file), your program should print out the desired area correct to two decimal places. The input will end with a line containing a zero (0).

Output

Output will consist of a single line containing the desired area written as a succession of eight (8) digit fields with two (2) digits after the decimal point. There will not be enough cases to need more than one line.

Sample Input

3  5 5  8 1  2 3
3  5 5  8 1  2 3
4  1 2  1 4  5 4  5 2
6  6 3  8 2  8 1  4 1  4 2  5 3
0

Sample Output

0.00
13.50

Problem solving report:

Description: 求出仅存在其中一个多边形的区域面积。
Problem solving: 利用半平面交求出重叠的面积,然后用总面积减去重叠面积的二倍就是答案。

Accepted Code:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 5;
const double eps = 1e-8;
typedef struct point {double x, y;
}vect;
struct line {vect p;point u, v;bool operator < (const line& s) const {return atan2(s.p.y, s.p.x) > atan2(p.y, p.x);}
}Sline[MAXN];
point p1[MAXN], p2[MAXN];
vect operator - (const point& a, const point& b) {return (vect){a.x - b.x, a.y - b.y};
}
int pnz(double x) {return x < -eps ? -1 : x > eps ? 1 : 0;
}
double Cross(const vect& a, const vect& b) {return a.x * b.y - a.y * b.x;
}
bool Onleft(const point& p, const line& l) {return pnz(Cross(l.p, p - l.u)) > 0;
}
point Inter(const line& a, const line& b) {double t = Cross(b.p, a.u - b.u) / Cross(a.p, b.p);return (point){a.u.x + t * a.p.x, a.u.y + t * a.p.y};
}
double Area(point p[], int n) {double area = 0;for (int i = 1; i < n - 1; i++)area += Cross(p[i] - p[0], p[i + 1] - p[0]);return area / 2;
}
double Halfplane(int n) {sort(Sline, Sline + n);int Q[n] = {0};point Spt[n];int l = 0, r = 0;for (int i = 1; i < n; i++) {while (l < r && !Onleft(Spt[r - 1], Sline[i]))r--;while (l < r && !Onleft(Spt[l], Sline[i]))l++;Q[++r] = i;if (!pnz(Cross(Sline[i].p, Sline[Q[r - 1]].p))) {r--;if (Onleft(Sline[i].u, Sline[Q[r]]))Q[r] = i;}else Spt[r - 1] = Inter(Sline[Q[r]], Sline[Q[r - 1]]);}while (l < r && !Onleft(Spt[r - 1], Sline[Q[l]]))r--;while (l < r && !Onleft(Spt[l], Sline[Q[r]]))l++;if (r - l <= 1)return 0;Spt[r] = Inter(Sline[Q[l]], Sline[Q[r]]);return Area(Spt + l, r - l + 1);
}
int main() {int n, m;while (scanf("%d", &n), n) {for (int i = n - 1; i >= 0; i--)scanf("%lf%lf", &p1[i].x, &p1[i].y);for (int i = 0; i < n; i++) {int j = (i + 1) % n;Sline[i] = (line){p1[j] - p1[i], p1[i], p1[j]};}scanf("%d", &m);for (int i = m - 1; i >= 0; i--)scanf("%lf%lf", &p2[i].x, &p2[i].y);for (int i = 0; i < m; i++) {int j = (i + 1) % m;Sline[i + n] = (line){p2[j] - p2[i], p2[i], p2[j]};}printf("%8.2f", Area(p1, n) + Area(p2, m) - 2 * Halfplane(n + m));}printf("\n");return 0;
}

HDU - Polygons(半平面交)相关推荐

  1. Polygons HDU - 1632 (半平面交)

    Polygons HDU - 1632 题意:求两个多边形的"异或"面积. 半平面交~ 1 #include <bits/stdc++.h> 2 using namespace std; ...

  2. HDU 6617 Enveloping Convex(凸包+半平面交+二分)

    首先对于这m个点维护出一个凸包M,那么问题就变成了判断凸包P进行放大缩小能不能包含凸包M.(凸包P可以进行中心对称变换再进行放大缩小,见题意) 如何判断合适的相似比呢,我们可以用二分去放大缩小凸包P的 ...

  3. [凸多边形最大内切圆][半平面交]Most Distant Point from the Sea POJ3525

    The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is na ...

  4. UVA1396 Most Distant Point from the Sea(AM - ICPC - Tokyo - 2007)(计算几何,半平面交 + 二分答案)

    整理的算法模板合集: ACM模板 题目传送门 见<训练指南>P279 很明显就是一个二分答案,它问的是最远的点,直接枚举因为这里都是double类型的数所以有无限个点,我们可以直接二分. ...

  5. POJ 1474 Video Surveillance(半平面交)

    题意:半平面交求多边形内核(我明明及的我之前是会用kuangbin第一份版平面交的,现在怎么就不会用了呢,补第二份代码) 代码: #include<cstdio> #include< ...

  6. LA 2218 (半平面交) Triathlon

    题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...

  7. POJ3335(半平面交)

    POJ3335 半平面交裸题 //poj3335 #include <cstdio> #include <cmath> #include <algorithm> # ...

  8. LA 3890 (半平面交) Most Distant Point from the Sea

    题意: 给出一个凸n边形,求多边形内部一点使得该点到边的最小距离最大. 分析: 最小值最大可以用二分. 多边形每条边的左边是一个半平面,将这n个半平面向左移动距离x,则将这个凸多边形缩小了.如果这n个 ...

  9. [BZOJ1007](HNOI2008)水平可见直线(半平面交习题)

    Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的.     例如,对于直线:   ...

  10. 半平面交练习(计算几何)

    四:半平面交 Rotating Scoreboard /*Author : lifehappy */ #include <cstdio> #include <cmath> #i ...

最新文章

  1. RabbitMQ 下载、安装、配置、验证_rpm版本(Linux环境)
  2. JVM学习--(二)内存模型、可见性、指令重排序
  3. ECCV 2020 | 小米提出 Fair DARTS :公平的可微分神经网络搜索
  4. WPF设计の自定义窗体
  5. 梯度下降法参数更新公式的推导
  6. 【报告分享】激荡2020--吴晓波疫情特别演讲PPT.pdf(附下载链接)
  7. 在O(1)时间复杂度删除链表节点(372)
  8. JSP+JSTL+EL表达式,实现web页面的页面跳转功能(上一页下一页首页末页页面跳转)
  9. QQ、微信动态图表情包怎么制作?视频如何转GIF
  10. gtj2018如何生成工程量报表_工程量清单计价规范2018
  11. JS 利用CNZZ进行站长统计
  12. 平凡的世界 田晓霞的日记 摘抄
  13. 新计算机如何用光盘安装系统,win7如何用光盘装系统_使用光盘重装win7系统步骤...
  14. 测试删除hive表时出错
  15. win10使计算机进入睡眠状态什么意思,win10如何进入睡眠模式 电脑睡眠模式设置教程...
  16. 串口重定向(STM32 F411RET6开发版)
  17. 从重大漏洞应急看云原生架构下的安全建设与安全运营(下)
  18. 在统计学中_[求助] OR在统计学中指什么?
  19. 银行计算机房处理监控设备,银行机房环境集中监控系统【斯必得智慧机房】
  20. Implement (interface)

热门文章

  1. Java 视频转码(转为MPEG-4格式)
  2. 有感于李连杰壹基金计划
  3. uniapp,小程序返回到指定页面以及到指定页面左上角的房型默认返回首页
  4. linux将汇编转为机器码,如何将汇编语言转化为机器码
  5. package crypto/rand: unrecognized import path crypto/rand (import path does not begin with hostnam
  6. 解决Ubuntu 20.04 虚拟机克隆出多台造成的IP地址冲突的问题
  7. Sqilabs第五关注入常用注入方式详解
  8. AdobeFlashPlayer发生安全沙箱冲突
  9. 提取Linux的下制作生成grldr,如何制作自己的LINUX系统?
  10. 安装pika配置系统服务过程中遇到的错误