题意:给定n个顶点和其坐标,问这n个顶点里挑四个能组成几个平行四边形
Sample Input
2
6
0 0
2 0
4 0
1 1
3 1
5 1
7
-2 -1
8 9
5 7
1 1
4 8
2 0
9 8
Sample Output
Case 1: 5
Case 2: 6
思路:
我过于愚蠢。 判断平行四边形最简单的形式就是对角线相互平分,所以只要找出中点相同的点对就可以了。
/**
**/
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#define eps 1e-8
typedef long long ll;
const double PI = acos(-1.0);
const int maxn = 1e6;
const int INF = 0x3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
using namespace std;
int n;
struct node
{
int x,y;
}p1[maxn+5],p2[maxn+5];
bool judge(int a, int b)
{
if(p2[a].x == p2[b].x && p2[a].y == p2[b].y)
return 1;
return 0;
}
bool cmp(node a, node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
//ios::sync_with_stdio(false);
int T;
scanf("%d",&T);
int tt = 1;
while(T--)
{
scanf("%d",&n);
for(int i = 0; i<n; i++)
scanf("%d %d",&p1[i].x,&p1[i].y);
int k = 0;
//计算所有不同点对的中点
for(int i = 0; i<n; i++)
for(int j = i+1; j<n; j++)
{
p2[k].x = (p1[i].x+p1[j].x);
p2[k++].y = (p1[i].y+p1[j].y);
}
ll cnt = 1,ans = 0;
sort(p2,p2+k,cmp);
for(int i = 1; i<k; i++)
{
if(judge(i,i-1))
cnt++;
else
{
ans += (cnt-1)*cnt/2;
cnt = 1;
}
}
ans += (cnt-1)*(cnt)/2;
printf("Case %d: %lld\n",tt++,ans);
}
return 0;
}