天天看点

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

​​传送门​​​ B. Eastern Exhibition

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

You and your friends live in n 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) and (x2,y2) is |x1−x2|+|y1−y2|, where |x| is the absolute value of x.

Input

First line contains a single integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤1000). Next n lines describe the positions of the houses (xi,yi) (0≤xi,yi≤109).

It’s guaranteed that the sum of all n does not exceed 1000.

思路

#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
ll x[1010],y[1010];
int main()
{
  int t;
  scanf("%d",&t);
  while(t--)
  {
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
    {
      scanf("%lld",&x[i]);
      scanf("%lld",&y[i]);
    }
    
    sort(x+1, x+1+n);
    sort(y+1, y+1+n);
    if(n%2)
    {
      printf("1\n");
    }
    else
    {
      ll lx = x[(n+1)/2],ly = y[(n+1)/2];
      ll rx = x[(n+1)/2+1],ry = y[(n+1)/2+1];
      
      ll ans = (rx - lx + 1)*(ry - ly + 1);
      if(ans == 0)
      printf("1\n");
      else
      printf("%lld\n",ans);
    }
  }
}