#P1850G. The Morning Star

    ID: 576 远端评测题 2000ms 256MiB 尝试: 6 已通过: 2 难度: 10 上传者: 标签>combinatoricsdata structuresgeometryimplementationmathsortings*1500

The Morning Star

题面翻译

题意简述

本题有多组数据。

给定 nn 个点,第 ii 个点的坐标为 xix_iyiy_i

现需要将星星和指南针放在任意两个点上,使得星星在指南针的正北、正东、正西、正南、正东南、正东北、正西南或正西北方向,求一共几种放法。(如果对此不太理解结合样例解释)

数据范围

2n21052\leq n \leq 2 \cdot 10^5

109xi,yi109-10^9\leq x_i,y_i \leq 10^9

输入格式

第一行输入一个tt,表示数据组数。

在每组数据中,输入nn,表示点的总数。

接下来 nn 行,第ii行输入两个数 xi,yix_i,y_i,表示第ii个点的坐标。

输出格式

输出共tt行,每行一个整数,表示第ii组数据的结果。

说明/提示

在第一组数据中:

指南针在 (0,0)(0,0),星星在 (1,1)(-1,-1),在指南针的正西南方向。

指南针在 (0,0)(0,0),星星在 (1,1)(1,1),在指南针的正东北方向。

指南针在 (1,1)(-1,-1),星星在 (0,0)(0,0),在指南针的正东北方向。

指南针在(1,1)(-1,-1),星星在(1,1)(1,1),在指南针的正东北方向。

指南针在(1,1)(1,1),星星在(0,0)(0,0),在指南针的正西南方向。

指南针在(1,1)(1,1),星星在(1,1)(-1,-1),在指南针的正西南方向。

所以答案为6。

在第二组数据中:

指南针在(6,9)(6,9),星星在(10,13)(10,13),在指南针的正东北方向。

指南针在(10,13)(10,13),星星在(6,9)(6,9),在指南针的正西南方向。

所以答案是 2。

题目描述

A compass points directly toward the morning star. It can only point in one of eight directions: the four cardinal directions (N, S, E, W) or some combination (NW, NE, SW, SE). Otherwise, it will break.

The directions the compass can point.There are n n distinct points with integer coordinates on a plane. How many ways can you put a compass at one point and the morning star at another so that the compass does not break?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases t t ( 1t104 1 \le t \le 10^4 ). The description of the test cases follows.

The first line of each test case contains a single integer n n ( 2n2105 2 \leq n \leq 2 \cdot 10^5 ) — the number of points.

Then n n lines follow, each line containing two integers xi x_i , yi y_i ( 109xi,yi109 -10^9 \leq x_i, y_i \leq 10^9 ) — the coordinates of each point, all points have distinct coordinates.

It is guaranteed that the sum of n n over all test cases doesn't exceed 2105 2 \cdot 10^5 .

输出格式

For each test case, output a single integer — the number of pairs of points that don't break the compass.

样例 #1

样例输入 #1

5
3
0 0
-1 -1
1 1
4
4 5
5 7
6 9
10 13
3
-1000000000 1000000000
0 0
1000000000 -1000000000
5
0 0
2 2
-1 5
-1 10
2 11
3
0 0
-1 2
1 -2

样例输出 #1

6
2
6
8
0

提示

In the first test case, any pair of points won't break the compass:

  • The compass is at (0,0) (0,0) , the morning star is at (1,1) (-1,-1) : the compass will point SW \text{SW} .
  • The compass is at (0,0) (0,0) , the morning star is at (1,1) (1,1) : the compass will point NE \text{NE} .
  • The compass is at (1,1) (-1,-1) , the morning star is at (0,0) (0,0) : the compass will point NE \text{NE} .
  • The compass is at (1,1) (-1,-1) , the morning star is at (1,1) (1,1) : the compass will point NE \text{NE} .
  • The compass is at (1,1) (1,1) , the morning star is at (0,0) (0,0) : the compass will point SW \text{SW} .
  • The compass is at (1,1) (1,1) , the morning star is at (1,1) (-1,-1) : the compass will point SW \text{SW} .

In the second test case, only two pairs of points won't break the compass:

  • The compass is at (6,9) (6,9) , the morning star is at (10,13) (10,13) : the compass will point NE \text{NE} .
  • The compass is at (10,13) (10,13) , the morning star is at (6,9) (6,9) : the compass will point SW \text{SW} .