题意:给n个点,问能组成的平行四边形的个数。
思路:平行四边形对角线交点唯一,算出有多少个相同的交点cnt,
sum+= (cnt*(cnt-1))/2;
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define ll long long
#define llu unsigned long long
using namespace std;
const double eps = 1e-8;
const double PI = 3.1415926;
struct Point {
double x,y;
Point (double x = 0,double y = 0) : x(x),y(y) {}
};
Point p[1050],s[1000500];
struct Line{
Point a,b;
};
Line line[100];
int indl,indp;
bool dcmp(double x) {
if(fabs(x)-0.0 <= eps) return true;
return false;
}
int n;
double l;
bool cmp(Point a,Point b) {
if(!dcmp(a.x-b.x)) return a.x<b.x;
return a.y<b.y;
}
Point A;
int main(){
int t; scanf("%d",&t);
for(int cas = 1; cas<=t; cas++){
int indx = 1;
scanf("%d",&n);
for(int i=1;i<=n; i++) {
scanf("%lf%lf",&p[i].x,&p[i].y);
for(int j=1; j<i; j++) {
s[indx].x = (p[i].x+p[j].x)/2;
s[indx].y = (p[i].y+p[j].y)/2;
indx++;
}
}
ll sum = 0;
ll ans = 1;
sort(s+1,s+indx,cmp);
A.x = s[1].x; A.y = s[1].y;
for(int i=2;i<indx;i++) {
if(dcmp(s[i].x-A.x) && dcmp(s[i].y-A.y)) {
ans++;
}else {
if(ans >= 2) {
sum += (ans*(ans-1)/2);
}
ans = 1;
A.x = s[i].x; A.y = s[i].y;
}
}
printf("Case %d: %lld\n",cas,sum);
}
return 0;
}