求凸多边形最远顶点距离
求出凸包后对凸包旋转卡壳即可。
#include#define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define fk cout<<"fk"< pii; typedef vector vi; typedef long long i64; template bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout< 1 && cross(z[m - 1] - z[m - 2], v[i] - z[m - 2]) <= 0) --m; z[m++] = v[i]; } int k = m; for(int i = n - 2; i >= 0; --i){ while(m > k && cross(z[m - 1] - z[m - 2], v[i] - z[m - 2]) <= 0) --m; z[m++] = v[i]; } if(n > 1) --m; return m; } void kake(vec *v, int v_len){ //旋转卡壳 double ans = 1e15; int idx = 1; v[v_len] = v[0]; for(int i = 0; i < v_len; ++i){ while(fabs(cross(v[i + 1] - v[i], v[idx + 1] - v[i])) > fabs(cross(v[i + 1] - v[i], v[idx] - v[i]))){ idx = (idx + 1) % v_len; } double now = fabs(cross(v[i + 1] - v[i], v[idx] - v[i])) / (v[i] - v[i + 1]).len(); if(sgn(now - ans) == -1) ans = now; } printf("%.8fn", ans); return; } int main() { fastio(); int n, r; scanf("%d%d", &n, &r); forn(i, n){ scanf("%lf%lf", &v[i].x, &v[i].y); } int tu_len = convex_hull(v, n, tu); kake(tu, tu_len); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)