题解 P9702【[GDCPC2023] Computational Geometry】
这题一看就不是计算几何,考虑区间 DP。
设凸多边形的 个顶点依次为 。
设 在 时表示 组成的多边形的直径的平方,在 时表示 组成的多边形的直径的平方。容易得到转移方程:
其中下标均为模 意义下。
答案即为每一对能将多边形分为两个面积为正的部分的点 中, 的最小值。其中, 能将多边形分为两个面积为正的部分,当且仅当 不共线,且 不共线,使用向量叉积计算即可。
时间复杂度 。
// 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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现