zoukankan      html  css  js  c++  java
  • CodeForces 660D Number of Parallelograms(n个点所能组成的最多平行四边形数量)

    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.

    Sample Input
    4
    0 1
    1 0
    1 1
    2 0
    Output
    1
    题意:

    给你n个点的坐标,问这n个点能形成多少个不相同的平行四边形?

    思路:

    (1) 根据平行四边形的性质,两条对角线相交于一点,所以可以将这n个点两两连接并找出它们的中点并记录下来。

    (2) 然后根据这些中点来判断有多少个平行四边形,因为只要有两个中点重合,那么就能确定一个平行四边形。

    (3) 所以先找出重合中点的个数s,那么它们可以组成的平行四边形个数为C(s,2)。将它们求和即可。

    #include<bits/stdc++.h>
    using namespace std;
    struct node
    {
        int x,y;
    }a[2005];
    int com(int n,int m)
    {
        int i,s=1;
        for(i=1;i<=m;i++)
        s=s*(n+1-i)/i;
        return s;
    } 
    int main()
    {
        int n,i,j,s=0;
        map<pair<int,int>,int>ma;
        map<pair<int,int>,int>::iterator it;
        cin>>n;
        for(i=1;i<=n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
            
        for(i=1;i<=n-1;i++)
            for(j=i+1;j<=n;j++)
                ma[make_pair(a[i].x+a[j].x,a[i].y+a[j].y)]++;
                
        for(it=ma.begin();it!=ma.end();it++)
            s=s+com(it->second,2);
            
        printf("%d
    ",s);
        return 0;
    }
  • 相关阅读:
    六、Doris数据流与控制流
    五、Doris数据分布
    非洛达芯片检测聚合教程NOT AIROHA CHIP
    慧联A8最新检测使用教程V2.0.3
    SpringBoot集成thymeleaf增删改查示例
    记一次Linux磁盘满盘/dev/vda1目录清理记录
    悦虎固件升级到底有啥用?二代为例
    PerfDog性能狗简介
    macOS常用命令
    像素格式与纹理压缩
  • 原文地址:https://www.cnblogs.com/kannyi/p/8835943.html
Copyright © 2011-2022 走看看