用两条边平行且相等,判断平行四边形。
把所有边转换成向量。mulitest 记录每种向量的个数,在统计
#include <bits/stdc++.h>
#define maxn 100005
#define INF 1e9
using namespace std;
typedef long long ll;
struct Node{
Node(){
}
Node(int a, int b){
x = a;
y = b;
}
int x, y;
ll len;
friend bool operator < (const Node &p1, const Node &p2){
if(p1.x == p2.x && p1.y == p2.y)
return p1.len < p2.len;
if(p1.x == p2.x)
return p1.y < p2.y;
return p1.x < p2.x;
}
};
int x[2005], y[2005];
multiset<Node> m;
int main(){
// freopen("in.txt", "r", stdin);
int n;
while(cin >> n){
m.clear();
for(int i = 0; i < n; i++){
scanf("%d%d", x+i, y+i);
}
ll cnt = 0;
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
int h1 = x[i] - x[j], h2 = y[i] - y[j];
Node p;
if(h1 == 0){
p = Node(h1, abs(h2));
}
else{
ll d = h1 * h2;
p = Node(abs(h1), d / abs(h1));
}
p.len = ((ll)h1 * h1 + (ll)h2 * h2);
cnt += m.count(p);
m.insert(p);
}
}
cout << cnt / 2 << endl;
}
return 0;
}