给出两个点集,然后求问来自己两个不同点集的点
(
x
1
,
y
1
)
(x_{1},y_{1})
(x1,y1)和
(
x
2
,
y
2
)
(x_{2},y_{2})
(x2,y2)构成的
(
x
1
+
x
2
,
y
1
+
y
2
)
(x_{1}+x_{2},y_{1}+y_{2})
(x1+x2,y1+y2)所组成的凸包的面积的两倍。
先对两个点集分别求凸包,然后双指针在凸包上扫描,每次假如更凸的那个边。
先存一个板子,虽然好像目前还存在不少问题。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=LONG_LONG_MAX;
const int N=2e5+7;
struct Point {
ll x,y;
Point() {}
Point(int _x,int _y):x(_x),y(_y) {}
bool operator <(const Point &rhs) const {
if(x<rhs.x) return 1;
else if(x==rhs.x&&y<rhs.y) return 1;
else return 0;
}
Point operator +(Point B) {
return Point(x+B.x,y+B.y);
}
Point operator -(Point B) {
return Point(x-B.x,y-B.y);
}
Point operator *(int k) {
return Point(k*x,k*y);
}
ll dot(Point B) {
return x*B.x+y*B.y;
}
ll det(Point B) {
return x*B.y-y*B.x;
}
}a[N],b[N],ch1[N],ch2[N],ch3[N],ch4[N];
int ConvexHull(Point a[],int n,Point ch[]) {
sort(a+1,a+1+n);
int tot=0;
for(int i=1;i<=n;i++) {
while(tot>1&&(ch[tot]-ch[tot-1]).det(a[i]-ch[tot])<0) tot--;
ch[++tot]=a[i];
}
int ctrl=tot;
for(int i=n-1;i>=1;i--) {
while(tot>ctrl&&(ch[tot]-ch[tot-1]).det(a[i]-ch[tot])<0) tot--;
ch[++tot]=a[i];
}
return tot;
}
int ConvexHull2(Point a[],int n,Point ch[]) {
sort(a+1,a+1+n);
int tot=0;
for(int i=1;i<=n;i++) {
while(tot>1&&(ch[tot]-ch[tot-1]).det(a[i]-ch[tot])<=0) tot--;
ch[++tot]=a[i];
}
int ctrl=tot;
for(int i=n-1;i>=1;i--) {
while(tot>ctrl&&(ch[tot]-ch[tot-1]).det(a[i]-ch[tot])<=0) tot--;
ch[++tot]=a[i];
}
return tot-1;
}
int Merge(Point ch1[],Point ch2[],Point ch[],int n,int m) {
int tot=0;
ch[++tot]=ch1[1]+ch2[1];
int i=1,j=1;
while(i+1<=n&&j+1<=m) {
Point n1=(ch1[i]+ch2[j+1])-ch[tot];
Point n2=(ch1[i+1]+ch2[j])-ch[tot];
if(n1.det(n2)<0) {
ch[++tot]=ch1[i+1]+ch2[j];i++;
}
else {
ch[++tot]=ch1[i]+ch2[j+1];j++;
}
}
for(;i<=n;i++) ch[++tot]=ch1[i]+ch2[m];
for(;j<=m;j++) ch[++tot]=ch2[j]+ch1[n];
return tot;
}
int main() {
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld%lld",&a[i].x,&a[i].y);
for(int i=1;i<=m;i++)
scanf("%lld%lld",&b[i].x,&b[i].y);
ll ans=0;
int sz1=ConvexHull(a,n,ch1);
int sz2=ConvexHull(b,m,ch2);
int tot=Merge(ch1,ch2,ch3,sz1,sz2);
int sz3=ConvexHull2(ch3,tot,ch4);
for(int i=2;i<sz3;i++)
ans+=(ch4[i]-ch4[1]).det(ch4[i+1]-ch4[1]);
printf("%lld\n",ans);
return 0;
}