学习链接:
计算几何凸包的概念和建立过程:https://blog.youkuaiyun.com/u013377068/article/details/80095620
旋转卡壳知识点详解:https://blog.youkuaiyun.com/qq_36172505/article/details/80228394
旋转卡壳宽度求解:https://blog.youkuaiyun.com/zhang20072844/article/details/6817734
例题:
Breaking Biscuits
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
typedef long long ll;
struct node
{
int x;
int y;
}p[maxn];
double callen(int x1, int y1, int x2, int y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll cross(int x1, int y1, int x2, int y2, int x3, int y3)
{
return (x3 - x1) * (y3 - y2) - (y3 - y1) * (x3 - x2);
}
int main()
{
int n;
int i, j, k;
double minlen = 1e18;
cin >> n;
for(i = 0; i < n; i++)
cin >> p[i].x >> p[i].y;
for(i = 0; i < n; i++)
for(j = i; j < n; j++)
{
ll low, high;
double len;
len = callen(p[i].x, p[i].y, p[j].x, p[j].y);
low = high = 0;
for(k = 0; k < n; k++)
{
ll s = cross(p[i].x, p[i].y, p[j].x, p[j].y, p[k].x, p[k].y);
low = min(low, s);
high = max(high, s);
}
minlen = min(minlen, (high - low) / len);
}
printf("%.9f", minlen);
return 0;
}
待更新。。。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
struct node
{
int x, y;
}p[maxn];
line operator -(node a, node b)
{
return line(a.x - b.y, a.y - b.x);
}
double callen(node a, node b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
ll cross(line a, line b)////
{
return a.x * b.y - a.y * b.x;
}
bool comp(node a, node b)
{
int crossval = cross(p[0], a, b);
return crossval > 0 || !crossval && callen(p[0], a) < callen(p[0], b);
}
int main()
{
int n;
int i, j, k;
cin >> n;
for(i = 0; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
int t = 0;
for(i = 1; i < n; i++)
if(p[i].x < p[t].x || p[i].x == p[t].x && p[i].y < p[t].y)
t = i;
swap(p[0], p[t]);
sort(p + 1, p + n, comp);
int s[maxn];
s[0] = p[0];
int top = 0;
for(i = 1; i < n; i++)
{
while(top > 0 && cross(p[top] - p[top - 1], p[top] - p[i]) >= 0)
top--;
s[++top] = p[i];
}
}