题解 P9702【[GDCPC2023] Computational Geometry】

这题一看就不是计算几何,考虑区间 DP。

设凸多边形的 n 个顶点依次为 P1,P2,,Pn

fi,ji<j 时表示 Pi,Pi+1,,Pj1,Pj 组成的多边形的直径的平方,在 i>j 时表示 Pi,Pi+1,,Pn,P1,,Pj1,Pj 组成的多边形的直径的平方。容易得到转移方程:

fi,j=max{fi+1,j,fi,j1,dis2(Pi,Pj)}

其中下标均为模 n 意义下。

答案即为每一对能将多边形分为两个面积为正的部分的点 (Pi,Pj) 中,fi,j+fj,i 的最小值。其中,(Pi,Pj) 能将多边形分为两个面积为正的部分,当且仅当 Pi1,Pi,Pj 不共线,且 Pi,Pi+1,Pj 不共线,使用向量叉积计算即可。

时间复杂度 O(n2)

// Problem: T368391 [GDCPC2023] M-Computational Geometry
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/T368391?contestId=135929
// Memory Limit: 1 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x, y, z) for(ll x = (y); x <= (z); ++x)
#define per(x, y, z) for(ll x = (y); x >= (z); --x)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do {freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);} while(false)
#define endl '\n'
using namespace std;
typedef long long ll;

mt19937 rnd(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
ll randint(ll L, ll R) {
    uniform_int_distribution<ll> dist(L, R);
    return dist(rnd);
}

template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

const ll N = 5e3 + 5;

ll T, n, x[N], y[N], diam[N][N];

inline ll sq(ll x) {return x * x;}
inline bool line(ll i, ll j, ll k) {
    ll v1x = x[i] - x[j], v1y = y[i] - y[j];
    ll v2x = x[i] - x[k], v2y = y[i] - y[k];
    return v1x * v2y - v2x * v1y == 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    for(cin >> T; T; --T) {
        cin >> n;
        rep(i, 0, n - 1) cin >> x[i] >> y[i];
        auto inc = [&](ll x) {return (x + 1) % n;};
        auto dec = [&](ll x) {return (x - 1 + n) % n;};
        rep(dt, 1, n - 1) {
            rep(L, 0, n - 1) {
                ll R = (L + dt) % n;
                diam[L][R] = max({diam[inc(L)][R], diam[L][dec(R)], sq(x[L] - x[R]) + sq(y[L] - y[R])});
            }
        }
        ll ans = numeric_limits<ll>::max();
        rep(i, 0, n - 1) {
            rep(j, 0, n - 1) {
                if(!line(dec(i), i, j) && !line(i, inc(i), j)) {
                    chkmin(ans, diam[i][j] + diam[j][i]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
posted @   rui_er  阅读(42)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示