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个点 ...
随机推荐
- Django_项目初始化
如何初始Django运行环境? 1. 安装python 2. 创建Django项目专用的虚拟环境 http://www.cnblogs.com/2bjiujiu/p/7365876.html 3.进入 ...
- js_8_dom标签
创:9_3_2017 星期4 修: 对于在a标签中,如何阻止跳转? 定义一个事件,事件顺序执行后才执行跳转,如果事件函数返回false,则后面事件就不触发 事件1 = "return 函数 ...
- border样式?
border样式? 设置边框样式: border:宽度 外形 颜色:(自动设置顺序:top,right,bottom,left) boeder-top:宽度 外形 颜色:(单独为某一个边边框设置样式) ...
- python_面向对象
什么是面向对象? -- 一种主流编程范式,编程思维框架,世界主流两个方向,面向对象和面向过程. -- 面向是把关注点集中一个具体东西,比如看向手机,也叫面向手机,手机就是一个对象,我们 把手机的属性 ...
- Unity 使用Plugins接入安卓SDK 基础篇
一.须知 本帖适合对安卓一点基础都没有,有一定Unity基础.刚刚接完一个某文档很简单的渠道SDk,也当是自己总结一下. 二.Unity中的目录创建与理解. Plugins:插件目录,该目录再编译项目 ...
- nginx把POST转GET请求解决405问题
405重定向,然后把POST转GET upstream local { server 10.0.1.11:81; } server { listen 81; server_name testf.xxx ...
- Tomcat修改端口号(7.0 version)
目的:有时端口号可能其他服务占用,就需要修改一下Tomcat的端口号,避免冲突. 自我总结,有什么需要改正的地方,请大家补充,感激不尽! 找到Tomcat的的配置文件server.xml 路径:%to ...
- JavaScript 优雅简单的拼接字符串
前言 最近维护一个老系统,里面有大量js拼接字符串的代码,这里总计一下js拼接字符串 JS 原生字符串拼接 JavaScript里面的字符串可以直接用 + 来拼接 return "<a ...
- python中用xpath匹配文本段落内容的技巧
content = item.xpath('//div[@class="content"]/span')[0].xpath('string(.)') content = item. ...
- CS231n-lecture2-Image Classification pipeline 课堂笔记
---恢复内容开始--- 相关资源 Event Type Date Description Course Materials Lecture 2 Thursday April 6 Image ...