题意

题目链接

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. linux(centos7)安装docker

    1.检查内核版本,必须是3.10及以上 uname ‐r 2.安装docker yum install docker 3.输入y确认安装 4.启动docker [root@localhost ~]# ...

  2. javascript知识整理之this

    js中的this是一个头疼的问题,尤其对于笔者这种初级的菜鸟来讲,下面梳理下this的知识,可以当做是初级进阶也好入门也罢,总归输出的才是自己掌握的: Js中this不是由词法作用域决定的 而是调用时 ...

  3. 仿B站项目——(1)计划,前端工程

    计划 现打算: 计划用webpack打包 + 模板语言 + jquery + jquery ui + bootstrap做一个仿B站的静态网站. 网站兼容手机浏览器端. 部分模块打算仿照SPA用js加 ...

  4. [Swift]扩展UIImage :获取图片指定像素的颜色值

    对[UIImage]进行扩展 import UIKit extension UIImage{ /** 根据坐标获取图片中的像素颜色值 */ subscript (x: Int, y: Int) -&g ...

  5. Ubuntu 13.10下安装ns2 2.35遇到的小问题

    前面下载安装的环节我就不多说了,网上已经有很多的例子,最全的是一个新浪网友写的博客:http://blog.sina.com.cn/s/blog_785a23ae0100xraq.html.他使用的是 ...

  6. Spring Boot Debug调试

    在使用spring-boot:run进行启动的时候,如果设置的断点进不去,要进行以下的设置. 1.添加jvm参数配置 在spring-boot的maven插件加上jvmArguments配置. < ...

  7. mint-ui Infinite scroll 重复加载、加载无效的原因及解决方案

    1.无限滚动的运用场景: 一般运用在列表展示,有分页.下拉加载更多的需求中. 2.代码分析 代码很简单,实现了列表分页,数据加载完之后显示数据状态 <template> <div c ...

  8. app自动化测试之实战应用(百度app简单测试)

    模拟在百度app中搜索python相关内容代码如下: from appium import webdriver desired_caps = {} desired_caps['deviceName'] ...

  9. Linux学习笔记之六————Linux常用命令之系统管理

    <1>查看当前日历:cal cal命令用于查看当前日历,-y显示整年日历: <2>显示或设置时间:date 设置时间格式(需要管理员权限): date [MMDDhhmm[[C ...

  10. Java连接Mysql数据库警告: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established

    详细错误: Establishing SSL connection without server's identity verification is not recommended. Accordi ...