A. Bovine Dilemma

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Argus was charged with guarding Io, which is not an ordinary cow. Io is quite an explorer, and she wanders off rather frequently, making Argus' life stressful. So the cowherd decided to construct an enclosed pasture for Io.

There are nn trees growing along the river, where Argus tends Io. For this problem, the river can be viewed as the OXOX axis of the Cartesian coordinate system, and the nn trees as points with the yy-coordinate equal 00. There is also another tree growing in the point (0,1)(0,1).

Argus will tie a rope around three of the trees, creating a triangular pasture. Its exact shape doesn't matter to Io, but its area is crucial to her. There may be many ways for Argus to arrange the fence, but only the ones which result in different areas of the pasture are interesting for Io. Calculate the number of different areas that her pasture may have. Note that the pasture must have nonzero area.

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow, each one is described in two lines.

In the first line of each test case there is a single integer nn (1≤n≤501≤n≤50) denoting the number of trees growing along the river. Next line contains nn distinct integers x1<x2<…<xn−1<xnx1<x2<…<xn−1<xn (1≤xi≤501≤xi≤50), the xx-coordinates of trees growing along the river.

Output

In a single line output an integer, the number of different nonzero areas that triangles with trees as vertices may have.

Example

input

Copy

8
4
1 2 4 5
3
1 3 5
3
2 6 8
2
1 2
1
50
5
3 4 5 6 8
3
1 25 26
6
1 2 4 8 16 32

output

Copy

4
2
3
1
0
5
3
15

Note

In the first test case, we have 66 non-degenerate triangles with the following areas: 0.50.5, 0.50.5, 11, 1.51.5, 1.51.5 and 22. The pasture can have 44 different areas, and thus 44 is the answer.

In the second test case, we have 33 non-degenerate triangles with the following areas: 11, 11 and 22. The pasture can have 22 different areas, so 22 is the answer.

The following two drawings present the situation in the second test case. The blue triangles in the first drawing have area 11. The red triangle in the second drawing has area 22.

 

解题说明:此题是一道模拟题,翻译过来其实是问有多少种面积不同的三角形,由于高度都为1,那么面积不同主要就是看横坐标上的点的差值不同的个数了,遍历判断即可。

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t, n, i, j, k, count;
	scanf("%d", &t);
	while (t--)
	{
		k = 0, count = 0;
		scanf("%d", &n);
		int a[n], b[n*n];
		for (i = 0; i<n; i++)
		{
			scanf("%d", &a[i]);
		}
		for (i = 0; i<n; i++)
		{
			for (j = i + 1; j<n; j++)
			{
				b[k] = a[j] - a[i];
				k++;
			}
		}
		for (i = 0; i<k; i++)
		{
			if (b[i] != -1)
			{
				count++;
				for (j = i + 1; j<k; j++)
				{
					if (b[i] == b[j])
					{
						b[j] = -1;
					}
				}
			}
		}
		printf("%d\n", count);
	}
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页