AtCoder Beginner Contest 215
二分出 min( | xi - xj | , | yi - yj | ),双指针维护是否存在满足条件的点对(i, j),假如二分当前值是x,那么 |xi - xj| >= x &&|yi - yj| >= x

#include<bits/stdc++.h> using namespace std; #define endl "\n" typedef long long ll; const int N = 2e5 + 5; struct Node{ int x, y; } a[N]; bool cmp(Node t1, Node t2){ return t1.x < t2.x; } int n; bool check(int x){ int maxn = INT_MIN, minn = INT_MAX; for(int i = 1, j = 1; i <= n; i++){ while(j < i && a[i].x - a[j].x >= x){ maxn = max(maxn, a[j].y); minn = min(minn, a[j].y); j++; } if(maxn >= a[i].y + x)return true; if(minn <= a[i].y - x)return true; } return false; } int main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; sort(a + 1, a + 1 + n, cmp); int L = 0, R = 1e9 + 10; while(L + 1 < R){ int M = (L + R) >> 1; if(check(M)) L = M; else R = M; } cout << L << endl; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】