当前位置:
首页 >
CodeForces - 1486B Eastern Exhibition(二维中位数)
发布时间:2024/4/11
42
豆豆
生活随笔
收集整理的这篇文章主要介绍了
CodeForces - 1486B Eastern Exhibition(二维中位数)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目链接:点击查看
题目大意:给出二维平面上的 nnn 个点,现在需要选择任意一个点满足到所有点的距离最小,问这样的点有几个
题目分析:如果压成一维的话,那就是一个裸的中位数问题了,只是升到了二维而已
一维的模型:CH - 0501 货仓选址
代码:
// Problem: B. Eastern Exhibition // Contest: Codeforces - Codeforces Round #703 (Div. 2) // URL: https://codeforces.com/contest/1486/problem/B // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) x&-x using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e6+100; LL x[N],y[N]; int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w;cin>>w;while(w--) {int n;read(n);for(int i=1;i<=n;i++) {read(x[i]);read(y[i]);}sort(x+1,x+1+n);sort(y+1,y+1+n);int l,r;if(n&1) {l=r=(n+1)/2;} else {l=n/2,r=n/2+1;}cout<<(x[r]-x[l]+1)*(y[r]-y[l]+1)<<endl;}return 0; } 超强干货来袭 云风专访:近40年码龄,通宵达旦的技术人生总结
以上是生活随笔为你收集整理的CodeForces - 1486B Eastern Exhibition(二维中位数)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: CodeForces - 165E Co
- 下一篇: CodeForces - 1486C2