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. 转载-Linux Shell 数组建立及使用技巧

    转载自:http://www.cnblogs.com/chengmo/archive/2010/09/30/1839632.html 如侵犯版权,请联系我删除 linux shell在编程方面比win ...

  2. junit源码解析--初始化阶段

    OK,我们接着上篇整理.上篇博客中已经列出的junit的几个核心的类,这里我们开始整理junit完整的生命周期. JUnit 的完整生命周期分为 3 个阶段:初始化阶段.运行阶段和结果捕捉阶段. 这篇 ...

  3. Jquery实现弹出层效果

    <script type="text/javascript"> $(document).ready(function(){ $('.one').click(functi ...

  4. Python-常用第三方库

    python常用框架及第三方库(转载) 一.Web框架 1.Django: 开源web开发框架,它鼓励快速开发,并遵循MVC设计,比较庞大,开发周期短.Django的文档最完善.市场占有率最高.招聘职 ...

  5. rsync命令解释

    -v, --verbose 详细模式输出-q, --quiet 精简输出模式-c, --checksum 打开校验开关,强制对文件传输进行校验-a, --archive 归档模式,表示以递归方式传输文 ...

  6. Struts2实现文件下载

    实现文件下载: 1.导包:commons-fileload-xx.jar commons-io-xx.jar 2.jsp页面: <s:iterator value="#session. ...

  7. c# excel print 打印 将所有列调整为一页

    excel有时候列数比较多,行数也比较多,转换成xps文档的时候,一般是通过打印来实现. 由于打印的范围限制,所以会出现本来在一行的数据,由于列数比较多,溢出范围,被打印到两页了. 为解决这个问题,需 ...

  8. thinkpadE470 win10安装虚拟机时出现‘intel VT-x’处于禁用状态 无法执行64位操作系统

    上图为安装虚拟机时弹出的问题. 解决办法: 本人电脑型号为thinkpadE470.遇到此问题查阅了很多,都是针对一般电脑的.折腾了好一会儿.故特写一篇针对此型号的. 1.重启计算机,一开始出现联想标 ...

  9. Python基础篇(五)

    bool用于判断布尔值的结果是True还是False >>> bool("a") True >>> bool(3) True >>& ...

  10. BZOJ 1434: [ZJOI2009]染色游戏

    一开始想这不$SG$裸题...然后发现100组数据...然后发现连通块是任意的求$SG$貌似要暴力枚举.... 然后想了一下1维,手动打表,每次就是队当前所有异或后缀和求$mex$,好像就是$lowb ...