当前位置:网站首页>B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
2022-07-24 03:07:00 【秦小咩】
B. Eastern Exhibition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You and your friends live in nn houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points (x1,y1)(x1,y1) and (x2,y2)(x2,y2) is |x1−x2|+|y1−y2||x1−x2|+|y1−y2|, where |x||x| is the absolute value of xx.
Input
First line contains a single integer tt (1≤t≤1000)(1≤t≤1000) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤1000)(1≤n≤1000). Next nn lines describe the positions of the houses (xi,yi)(xi,yi) (0≤xi,yi≤109)(0≤xi,yi≤109).
It's guaranteed that the sum of all nn does not exceed 10001000.
Output
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
Example
input
Copy
6 3 0 0 2 0 1 2 4 1 0 0 2 2 3 3 1 4 0 0 0 1 1 0 1 1 2 0 0 1 1 2 0 0 2 0 2 0 0 0 0
output
Copy
1 4 4 4 3 1
Note
Here are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.
First test case.
Second test case.
Third test case.
Fourth test case.
Fifth test case.
Sixth test case. Here both houses are located at (0,0)(0,0).
对于X,Y的选取两者互不影响,曼哈顿距离仅仅是XY差值的和,故只需要让X,Y分别取最小即可,也就转化成了一维问题,在一个线段上,奇数个点曼哈顿距离之和最小点在其中点,偶数个点其曼哈顿距离之和最小点在中间两点形成的闭区间之内。
# include<iostream>
# include<complex.h>
# include<string.h>
# include<cstring>
# include<vector>
# include<algorithm>
# include<iomanip>
using namespace std;
typedef complex<double>cp;
# define mod 9999991
typedef long long int ll;
ll x[1010],y[1010];
int main ()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i];
cin>>y[i];
}
if(n&1)
{
cout<<1<<'\n';
continue;
}
sort(x+1,x+1+n);
sort(y+1,y+1+n);
ll L,R;
L=x[n/2+1]-x[n/2]+1;
R=y[n/2+1]-y[n/2]+1;
cout<<L*R<<'\n';
}
return 0;
}
边栏推荐
- Summernote font displays Chinese
- Honey, we are homeless now
- JS 数组 isAarray() typeof
- Summernote supports custom video upload function
- 在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
- Example of producer consumer code implemented by the destructor framework without lock
- LCD1602 - binge 51
- [hdlbits questions] Verilog language (2) vectors
- Skywalking distributed system application performance monitoring tool - upper
- MySQL sub database and sub table and its smooth expansion scheme
猜你喜欢

I developed an app similar to wechat runnable applet with fluent

Microsoft win11/10 package manager Winget will support the installation of applications from zip files

MySQL sub database and sub table and its smooth expansion scheme

Attack and defense world web practice area (backup, cookie, disabled_button)

Acwing 4498. pointer (DFS)

Relational expression greater than > less than < congruence = = = Nan isnan() logical operator double sense exclamation point!! & |% +-- Short circuit calculation assignment expression shortcut operat

实现两个页面之前的通信(使用localStorage)

The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"

TCP connection principle

Basic knowledge of trigger (Part 2)
随机推荐
go errors
Attack and defense world web practice area (weak_auth, simple_php, xff_referer)
Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]
[C language] file operation
Generate 13 bit barcode
日常杂谈(一)
uva1445
Summernote rich text editor
Basic use of Pinia
Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
Unscramble the category and application principle of robot vision
Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
Example of producer consumer code implemented by the destructor framework without lock
Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework
AcWing 4498. 指针 (DFS)
攻防世界WEB练习区(weak_auth、simple_php、xff_referer)
JMeter interview script
SkyWalking分布式系统应用程序性能监控工具-上
Job hunting and recruitment system of SSM part-time job hunting
kettle