B. Eastern Exhibition- Codeforces Round #703 (Div. 2)

Problem - 1486B - Codeforces

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值