链接:戳这里
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个点,能组成多少个平行四边形
保证三点不共线,不出现重点
思路:
保证不共线的话则一条向量只能对应一个平行四边形
所以就变得很简单了,统计相同向量然后/2
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
int n;
struct point{
int x,y;
point(int x=0,int y=0):x(x),y(y){}
}s[2020];
typedef point vec;
point operator + (point a,point b){
return point(a.x+b.x,a.y+b.y);
}
point operator - (point a,point b){
return point(a.x-b.x,a.y-b.y);
}
map< pair<int,int>, int> mp;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&s[i].x,&s[i].y);
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
vec v=s[i]-s[j];
if(v.x==0 && v.y<0) v.y=-v.y;
else if(v.x<0) v.x=-v.x,v.y=-v.y;
ans+=mp[make_pair(v.x,v.y)];
mp[make_pair(v.x,v.y)]++;
}
}
printf("%I64d\n",ans/2);
return 0;
}