题目链接:

D. Number of Parallelograms

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

题意:

给了这么些点,问能形成多少个平行四边形;

思路:

把所有的线段找出来,按长度排序,平行四边形对边长度相等且互相平行,然后判断一下就好了,我的由于每个都算了4遍,所以最后/4;
比赛还没完我就写题解了,说不定还要被hack,好方,哈哈哈哈; AC代码:
/*
2014300227 660D - 4 GNU C++11 Accepted 468 ms 80348 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+;
typedef long long ll;
const double PI=acos(-1.0);
int n,cnt=,vis[*N];
ll x[],y[];
struct Line
{
int fi,se;
ll le;
};
Line line[*N];
int cmp(Line a,Line b)
{
return a.le<b.le;
}
int findpos(ll num)
{
int l=,r=cnt-,mid;
while(l<=r)
{
mid=(l+r)>>;
if(line[mid].le<num)l=mid+;
else r=mid-;
}
return l;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%I64d%I64d",&x[i],&y[i]);
}
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
line[cnt].fi=i;
line[cnt].se=j;
line[cnt++].le=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
} sort(line+,line+cnt,cmp);
vis[]=;
for(int i=;i<cnt;i++)
{
if(line[i].le==line[i-].le)
{
vis[i]=vis[i-];
}
else vis[i]=i;
}
int ans=;
for(int i=;i<cnt;i++)
{
int pos=vis[i];
for(int j=pos;j<cnt;j++)
{
if(line[j].le>line[i].le)break;
if(line[j].fi==line[i].se||line[j].se==line[i].fi||line[j].fi==line[i].fi||line[j].se==line[i].se)continue;
int cx,cy,dx,dy;
cx=line[i].fi;
cy=line[i].se;
dx=line[j].fi;
dy=line[j].se;
if((x[cx]-x[cy])*(y[dx]-y[dy])==(y[cx]-y[cy])*(x[dx]-x[dy]))
ans++;
}
}
cout<<ans/<<"\n"; return ;
}

codeforces 660D D. Number of Parallelograms(计算几何)的更多相关文章

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

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

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

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

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

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

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

  5. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

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

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

  7. D. Number of Parallelograms

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

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

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

  9. CodeForces 660D Number of Parallelograms

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

随机推荐

  1. Web前端学习攻略

    HTML+CSS: HTML进阶.CSS进阶.div+css布局.HTML+css整站开发. JavaScript基础: Js基础教程.js内置对象常用方法.常见DOM树操作大全.ECMAscript ...

  2. php的特殊功能-----不是和其他语言比较

    1.header(); 他不只是重定向,和更改字符集 而是发送表头,如 header('HTTP/1.1 404 Not Found   gfdgd'); 可以发送信息给浏览器,让浏览器显示404错误 ...

  3. (webstorm的CSS插件)前端开发必备!Emmet使用手册

    介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具: 基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为“片段”.虽然片段能很好地推动你得生 ...

  4. MariaDB mysql 比较区别 选择

    MariaDB数据库管理系统是MySQL的一个分支 开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险. MariaDB的目的是 ...

  5. 04 redis list结构及命令详解

    一:link 链表结构 lpush key value 作用: 把值插入到链接头部[右边] 注意:rpush key value 插入到左边 rpop key 作用: 返回并删除链表尾元素 rpush ...

  6. 在diy的文件系统上创建文件的流程

    [0]README 0.1) source code are from orange's implemention of a os , and for complete code , please v ...

  7. win732 安装hadoop

    windows下安装hadoop http://www.cnblogs.com/coder2012/archive/2013/05/25/3096631.html硬盘格式应为NTFS1 下载安装 Cy ...

  8. win本地配置docker环境

    先上官网链接:https://docs.docker.com/get-started/part2/#introduction 优质入门教程:http://www.docker.org.cn/book/ ...

  9. java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;

    spring3_hibernate 集成报错信息 java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljav ...

  10. python 基础 2.8 python练习题

    python 练习题:   #/usr/bin/python #coding=utf-8 #@Time   :2017/10/26 9:38 #@Auther :liuzhenchuan #@File ...