题意

题目链接

Sol

这个东西的学名应该叫“闵可夫斯基和”。就是合并两个凸包

首先我们先分别求出给出的两个多边形的凸包。合并的时候直接拿个双指针扫一下,每次选最凸的点就行了。

复杂度\(O(nlogn + n)\)

#include<bits/stdc++.h>
#define LL long long
//#define int long long
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M;
struct Point {
LL x, y;
Point operator - (const Point &rhs) const {
return {x - rhs.x, y - rhs.y};
}
Point operator + (const Point &rhs) const {
return {x + rhs.x, y + rhs.y};
}
LL operator ^ (const Point &rhs) const {
return x * rhs.y - y * rhs.x;
}
bool operator < (const Point &rhs) const {
return x == rhs.x ? y < rhs.y : x < rhs.x;
}
bool operator == (const Point &rhs) const {
return x == rhs.x && y == rhs.y;
}
bool operator != (const Point &rhs) const {
return x != rhs.x || y != rhs.y;
}
};
vector<Point> v1, v2;
Point q[MAXN];
int top;
void insert(Point a) {
while(top > 1 && ((q[top] - q[top - 1]) ^ (a - q[top - 1])) < 0) top--;
q[++top] = a;
}
void GetConHull(vector<Point> &v) {
sort(v.begin(), v.end());
q[++top] = v[0];
for(int i = 1; i < v.size(); i++) if(v[i] != v[i - 1]) insert(v[i]);
for(int i = v.size() - 2; i >= 0; i--) if(v[i] != v[i + 1]) insert(v[i]);
v.clear();
for(int i = 1; i <= top; i++) v.push_back(q[i]); top = 0;
}
void Merge(vector<Point> &a, vector<Point> &b) {
vector<Point> c;
q[++top] = a[0] + b[0];
int i = 0, j = 0;
while(i + 1 < a.size() && j + 1< b.size()) {
Point n1 = (a[i] + b[j + 1]) - q[top], n2 = (a[i + 1] + b[j]) - q[top];
if((n1 ^ n2) < 0)
q[++top] = a[i + 1] + b[j], i++;
else
q[++top] = a[i] + b[j + 1], j++;
}
for(; i < a.size(); i++) q[++top] = a[i] + b[b.size() - 1];
for(; j < b.size(); j++) q[++top] = b[j] + a[a.size() - 1];
for(int i = 1; i <= top; i++) c.push_back(q[i]);
LL ans = 0;
//for(auto &g : c) printf("%d %d\n", g.x, g.y);
for(int i = 1; i < c.size() - 1; i++)
ans += (c[i] - c[0]) ^ (c[i + 1] - c[0]);
cout << ans;
}
signed main() {
N = read(); M = read();
for(int i = 1; i <= N; i++) {
int x = read(), y = read();
v1.push_back({x, y});
}
for(int i = 1; i <= M; i++) {
int x = read(), y = read();
v2.push_back({x, y});
}
GetConHull(v1);
GetConHull(v2);
Merge(v1, v2);
return 0;
}
/*
4 5
0 0 2 1 0 1 2 0
0 0 1 0 0 2 1 2 0 1
*/

BZOJ2564: 集合的面积(闵可夫斯基和 凸包)的更多相关文章

  1. bzoj2564: 集合的面积(闵可夫斯基和 凸包)

    题面 传送门 题解 花了一个下午的时间调出了一个稍微能看的板子--没办法网上的板子和咱的不太兼容-- 首先有一个叫做闵可夫斯基和的东西,就是给你两个点集\(A,B\),要你求一个点集\(C=\{x+y ...

  2. bzoj2564集合的面积

    题目描述 对于一个平面上点的集合P={(xi,yi )},定义集合P的面积F(P)为点集P的凸包的面积. 对于两个点集A和B,定义集合的和为: A+B={(xiA+xjB,yiA+yjB ):(xiA ...

  3. bzoj2564 集合的面积

    Description 对于一个平面上点的集合P={(xi,yi )},定义集合P的面积F(P)为点集P的凸包的面积. 对于两个点集A和B,定义集合的和为: A+B={(xiA+xjB,yiA+yjB ...

  4. bzoj 2564 集合的面积

    Description 对于一个平面上点的集合P={(xi,yi )},定义集合P的面积F(P)为点集P的凸包的面积. 对于两个点集A和B,定义集合的和为: A+B={(xiA+xjB,yiA+yjB ...

  5. 洛谷P4557 [JSOI2018]战争(闵可夫斯基和+凸包)

    题面 传送门 题解 看出这是个闵可夫斯基和了然而我当初因为见到这词汇是在\(shadowice\)巨巨的\(Ynoi\)题解里所以压根没敢学-- 首先您需要知道这个 首先如果有一个向量\(w\)使得\ ...

  6. HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)

    题目链接   题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...

  7. poj 3348:Cows(计算几何,求凸包面积)

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6199   Accepted: 2822 Description ...

  8. UVa 10652(旋转、凸包、多边形面积)

    要点 凸包显然 长方形旋转较好的处理方式就是用中点的Vector加上旋转的Vector,然后每个点都扔到凸包里 多边形面积板子求凸包面积即可 #include <cstdio> #incl ...

  9. 闵可夫斯基和(Mincowsky sum)

    一.概述 官方定义:两个图形A,B的闵可夫斯基和C={a+b|a∈A,b∈B}通俗一点:从原点向图形A内部的每一个点做向量,将图形B沿每个向量移动,所有的最终位置的并便是闵可夫斯基和(具有交换律) 例 ...

随机推荐

  1. python 使用多进程实现并发编程/使用queue进行进程间数据交换

    import time import os import multiprocessing from multiprocessing import Queue, pool ""&qu ...

  2. Python队列及在微信机器人中的应用

    本文来源于i春秋学院,未经允许严禁转载. 最近打算更新微信机器人,发现机器人的作者将代码改进了很多,但去掉了sqlite数据库,需要自己根据需求设计数据库,跟作者沟通得到的建议是为了防止消息并发导致数 ...

  3. HTML和CSS使用注意事项

    HTML 1.button标签 在IE中,button标签默认的type是button,而在其他浏览器和W3C标准中button默认的属性都是submit. 所以,在一个form表单中,如果butto ...

  4. Testing - 软件测试杂谈

    Part-1 起步 测试是发现质量问题.分析.跟踪.推动与解决的过程. 1 熟悉业务,设计优质的测试用例,需要对所测试项目的业务需求非常熟悉 了解整个产品的研发和测试流程 全程参与,对需求.设计.开发 ...

  5. 21-json pickle shelve XML

    我们把对象从内存中变成可存储或传输的过程称之为序列化 在python中叫picking 在其他语言中也被称之为 serialization marshalling flattening等等 序列化之后 ...

  6. Python函数——闭包延迟绑定

    前言 请看下面代码 def multipliers(): return [lambda x : i*x for i in range(4)] print ([m(2) for m in multipl ...

  7. hdu 6058---Kanade's sum(链表)

    题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...

  8. IOS返回go(-1)

    IOS8和9,在用go(-1)返回的时候,会同时加载js.可能会造成js加载顺序出错,或者值被覆盖的情况,我们可以用setTimeout(function(){XXX代码},100);延时加载.

  9. cannot download, /home/azhukov/go is a GOROOT, not a GOPATH

    问题详情: go环境安装好后,运行go代码也没有问题 下载govendor包的时候提示: cannot download, /home/azhukov/go is a GOROOT, not a GO ...

  10. Spark SQL读取hive数据时报找不到mysql驱动

    Exception: Caused by: org.datanucleus.exceptions.NucleusException: Attempt to invoke the "BoneC ...