题目链接:Codeforces 660D Number of Parallelograms
D. Number of Parallelograms
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.
Output
Print the only integer c — the number of parallelograms with the vertices at the given points.
Example
input
4
0 1
1 0
1 1
2 0
output
1
题意:n个点,问你最多可以构成的平行四边形。
老题啦,平行四边形对角线中点重合,所以找中点就好了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define ll o<<1
#define rr o<<1|1
#define CLR(a, b) memset(a, (b), sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<double, double> pii;
const int INF = 0x3f3f3f3f;
const int MAXN = 3*1e5 + 10;
double x[2010], y[2010];
pii ans[2001*2001];
map<pii, int> fp;
int main()
{
int n;
while(scanf("%d", &n) != EOF) {
for(int i = 1; i <= n; i++) {
scanf("%lf%lf", &x[i], &y[i]);
}
fp.clear(); int top = 0;
for(int i = 1; i <= n; i++) {
for(int j = i+1; j <= n; j++) {
double xx = (x[i] + x[j]) / 2;
double yy = (y[i] + y[j]) / 2;
fp[pii(xx, yy)]++;
ans[top++] = pii(xx, yy);
}
}
sort(ans, ans+top);
int N = unique(ans, ans+top) - ans;
LL res = 0;
for(int i = 0; i < N; i++) {
int v = fp[ans[i]];
res += 1LL * v * (v-1) / 2;
}
printf("%lld\n", res);
}
return 0;
}