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;
}