CodeForces - 1486B Eastern Exhibition(二维中位数)

Posted Frozen_Guardian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1486B Eastern Exhibition(二维中位数)相关的知识,希望对你有一定的参考价值。

题目链接:点击查看

题目大意:给出二维平面上的 n n n 个点,现在需要选择任意一个点满足到所有点的距离最小,问这样的点有几个

题目分析:如果压成一维的话,那就是一个裸的中位数问题了,只是升到了二维而已

一维的模型: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;
}

以上是关于CodeForces - 1486B Eastern Exhibition(二维中位数)的主要内容,如果未能解决你的问题,请参考以下文章

活动回顾| Easter Bash!嗨到爆的复活节狂欢派对

[P1580] yyy loves Easter_Egg I

P1580-yyy loves Easter_Egg I

[洛谷P1580]yyy loves Easter_Egg I

yyy loves Easter_Egg I(恶心的字符串模拟)

css WebKit媒体查询电子邮件。 - https://litmus.com/blog/the-5-email-easter-eggs-that-helped-sell-out-the-emai