Educational Codeforces Round 11 D 计算几何



链接:戳这里


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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值