33,008
社区成员
发帖
与我相关
我的任务
分享
package com.yaowei.acm.problem_19xx;
import java.util.Arrays;
import java.util.Scanner;
public class Problem_1971 {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int caseCount = scanner.nextInt();
scanner.nextLine();
Point[] pArray;
for (int i = 0; i < caseCount; i++) {
int line = scanner.nextInt();
scanner.nextLine();
String s = "";
int result = 0;
long[] x = new long[line];
long[] y = new long[line];
for (int j = 0; j < line; j++) {
x[j] = scanner.nextLong();
y[j] = scanner.nextLong();
scanner.nextLine();
}// 一个case接收完毕
pArray = new Point[line * (line - 1) / 2];
int count = 0;
// 开始计算结果
for (int j = 0; j < line - 1; j++) {
for (int k = j + 1; k < line; k++) {
pArray[count++] = new Point(x[j] + x[k], y[j] + y[k]);
}
}
// 计算结果完毕
if (pArray.length < 2) {
System.out.println(0);
} else {
Arrays.sort(pArray);
long tempx = pArray[0].x;
long tempx1 = 0;
long tempy1 = 0;
long tempy = pArray[0].y;
int tempCount = 1;
for (int k = 1; k < pArray.length; k++) {
tempx1 = pArray[k].x;
tempy1 = pArray[k].y;
if (tempx1 == tempx && tempy1 == tempy) {
tempCount++;
} else {
tempx = tempx1;
tempy = tempy1;
if (tempCount > 1) {
result = result + (tempCount * (tempCount - 1) / 2);
}
tempCount = 1;
// // }
}
}
System.out.println(result);
}
}
}
}
class Point implements Comparable<Point> {
public long x;
public long y;
public Point(long x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(Point p) {
if (this.x < p.x) {
return -1;
}
if (this.x > p.x) {
return 1;
}
if (this.y > p.y) {
return 1;
}
if (this.y < p.y) {
return -1;
}
return 0;
}
}