CodeForces - 1486B Eastern Exhibition(二维中位数)
生活随笔
收集整理的這篇文章主要介紹了
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