D. Number of Parallelograms
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的更多相关文章
- Number of Parallelograms(求平行四边形个数)
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- 【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 ...
- codeforces 660D D. Number of Parallelograms(计算几何)
题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- D. Number of Parallelograms 解析(幾何)
Codeforce 660 D. Number of Parallelograms 解析(幾何) 今天我們來看看CF660D 題目連結 題目 給你一些點,求有多少個平行四邊形. 前言 @copyrig ...
- codeforce 660D Number of Parallelograms
题意:询问多少个矩形. 统计横纵坐标差,放进vector中 #include<cstdio> #include<cstring> #include<iostream> ...
- CodeForces 660D Number of Parallelograms
枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...
- CodeForces - 660D:Number of Parallelograms (问N个点多少个平行四边形)
pro:给定N个点,问多少个点组成了平行四边形.保证没有三点共线. sol:由于没有三点贡献,所以我们枚举对角线,对角线的中点重合的就是平行四边形.如果没说保证三点不共线就不能这么做,因为有可能4个点 ...
随机推荐
- PHP读取XML文件
xml主键被json取代,大概了解一下就OK了 简要: 加载xml文件:$xml = simplexml_load_file('sa.xml');//$xml是一个对象 读取节点:echo $xml- ...
- 【转】C++易混知识点3. New Operator, Operator New, Placement New 实例分析,比较区别
我们知道,C++中引入了New 这个内置符号,很大方便了指针的使用,程序员不必关注与这块堆上新分配的内存是如何来的,如何初始化的,然后如何转换为我们想要的类型指针的.现在,我们重点来分析下这个NEW内 ...
- 【转】globk和glorg中使用的apr文件
gamit和globk分析设置先验坐标和速度的要求和规则是不同的,因为在不同的阶段和环境下需要不同.从相位数据和松弛约束坐标和它们的方差得到的精 密坐标的可靠估计是假设对先验值的调整很小,也就是说在调 ...
- 【转】awk数组操作
转自:http://blog.csdn.net/wangran51/article/details/9168361 用awk进行文本处理,少不了就是它的数组处理.那么awk数组有那些特点,一般常见运算 ...
- PAT basic level 1001-1019 解题笔记
1002 写出这个数 采用字符串输入数据,再对每位减去字符‘0’,得到该位相应的整数 int len=s.length();//字符串的长度 ; ;i<len;i++)//每位减去‘0’,逐位相 ...
- .NET框架(转)
三年前写的<.NET之美>的第六章,现在书名改为了<.NET专题解析>. 本书是一本讲解.NET技术的书籍,目标读者群也是在.NET框架(.NET Framework)下进行开 ...
- 关于if和else嵌套—蛋疼
嵌套使用的时候else if和else遵循就近原则,和上面最靠近该语句的if语句匹配,要把else if看成是一个整体.就这么干,这样好理解一点. 一个if...else if...else语句中可以 ...
- 创建分模块的maven项目
折腾了我2天的maven,整理一下,以后做个参考 一.什么是maven项目: Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. Maven ...
- IE7、IE8不兼容js trim函数的解决方法
IE兼容,有时候让人头疼,但又不得不去解决. 先看看一下代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh ...
- 获取sap登陆用户名的中文描述
一.业务场景: 当通过MKPF-USNAM查找ADRP-NAME_LAST时,中间缺少一个表,即USR21.否则,MKPF-USNAM不能和ADRP-PERSNUMBER直接对等. 二.解决方法: D ...