D. Number of Parallelograms

原题链接

time limit per test

4 seconds

memory limit per test

256 megabytes

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

题目大意:给出一堆点,求出这些点中能组成平行四边形的个数,且题目要求没有三个点在同一直线上。

思路分析:判断平行四边形的方法有两种,一种是两边平行且相等,另一种就是中点相等。如果对角线上的两点的中点坐标在同一点,即满足(x1+x2)/2==(x3+x4)/2&&(y1+y2)/2==(y3+y4)/2条件,则说明这四个点能够构成一个平行四边形。首先求出任意两点之间的中点,再使用map,即可快捷求出每个中点所对应的平行四边形个数。

AC代码:

#include <cstdio>
#include <map>
#include <iostream>
using namespace std;
const int maxn=2000+5;
pair<long long ,long long>b[maxn];
map<pair<int,int>,int>sum;
int main(void)
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    scanf("%d%d",&b[i].first,&b[i].second);
    int count=0;
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
        {
            int x=b[i].first+b[j].first;
            int y=b[i].second+b[j].second;
            count+=sum[make_pair(x,y)]++;
        }
    cout<<count<<endl;
}

D. Number of Parallelograms的更多相关文章

  1. Number of Parallelograms(求平行四边形个数)

    Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  2. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  3. 【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 ...

  4. codeforces 660D D. Number of Parallelograms(计算几何)

    题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...

  5. Number of Parallelograms CodeForces - 660D (几何)

    Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...

  6. D. Number of Parallelograms 解析(幾何)

    Codeforce 660 D. Number of Parallelograms 解析(幾何) 今天我們來看看CF660D 題目連結 題目 給你一些點,求有多少個平行四邊形. 前言 @copyrig ...

  7. codeforce 660D Number of Parallelograms

    题意:询问多少个矩形. 统计横纵坐标差,放进vector中 #include<cstdio> #include<cstring> #include<iostream> ...

  8. CodeForces 660D Number of Parallelograms

    枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...

  9. CodeForces - 660D:Number of Parallelograms (问N个点多少个平行四边形)

    pro:给定N个点,问多少个点组成了平行四边形.保证没有三点共线. sol:由于没有三点贡献,所以我们枚举对角线,对角线的中点重合的就是平行四边形.如果没说保证三点不共线就不能这么做,因为有可能4个点 ...

随机推荐

  1. Storm容错和高可用

    Daemon Fault Tolerance Storm有一些不同的守护进程 Nimbus负责调度workers supervisors负责运行和杀死workers log views负责访问日志 U ...

  2. TP手册学习第三天

    命令行先在cmd进入项目目录,再执行命令 生成index模块的Blog控制器类库文件:php think make:controller index/Blog 如果仅仅生成空的控制器则可以使用:php ...

  3. 【转】GPS网平差

    进行GPS网平差的目的主要有三个: (1)消除由观测量和已知条件中存在的误差所引起的GPS网在几何上的不一致.包括闭合环闭合差不为0:复测基线较差不为0:通过由基线向量所形成的导线,将坐标由一个已知点 ...

  4. 【转】GPS连续运行单参考站解决方案

    GPS连续运行单参考站解决方案   一.  前言 随着国家信息化程度的提高及计算机网络和通信技术的飞速发展,电子政务.电子商务.数字城市.数字省区和数字地球的工程化和现实化,需要采集多种实时地理 空间 ...

  5. 【Thinkphp 5】auth权限设置以及实现

    1.将auth类下载好 放置目录: extend\auth\auth.php 2.将类中的SQL语句执行,可以在数据库中创建3张表 auth_group(用户组表)           auth_ru ...

  6. asp.net 发布程序到iis后无法连接到oralce数据库问题

    在应用程序池里面,选中你的站点所使用的应用程序池->高级设置->启用32位应用程序->true

  7. Effective Java 之 --- 用私有构造器或者枚举类型强化Singleton属性

    Singleton指仅仅被实例化一次的类,通常用来代表那些本质上唯一的系统组件,实现Singleton有三种方法: 1)公有静态成员是个final域,享有特权的用户可以调用AccessibleObje ...

  8. 精通libGDX游戏开发-RPG实战-欢迎来到RPG的世界

    欢迎来到RPG的世界 本章我会快速的使用tiled这样的瓷砖地图工具,来带领大家创造所设想的世界. 创建并编辑瓷砖地图 瓷砖地图(tile-based map)是广泛应用于各种游戏类型的地图格式,li ...

  9. 通过SMTP发送邮件的Python代码

    贴上一段用Python开发的发送邮件程序 #coding=UTF-8 import smtplib from email.mime.text import MIMEText smtp_host=&qu ...

  10. vue 学习中 版本、问题集锦

    看学习视频,因为年份比较早了,其实vue早已迭代到vue2.0了,遇到一些问题: v-for遍历数组,获取索引 注意:在2.0版是1~10中,$index已废除,索引 (item,index). 如下 ...