codeforces 660D D. Number of Parallelograms(计算几何)
题目链接:
4 seconds
256 megabytes
standard input
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.
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.
Print the only integer c — the number of parallelograms with the vertices at the given points.
4
0 1
1 0
1 1
2 0
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(计算几何)的更多相关文章
- 【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:Number of Parallelograms (问N个点多少个平行四边形)
pro:给定N个点,问多少个点组成了平行四边形.保证没有三点共线. sol:由于没有三点贡献,所以我们枚举对角线,对角线的中点重合的就是平行四边形.如果没说保证三点不共线就不能这么做,因为有可能4个点 ...
- Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms CodeForces - 660D You are given n points on a plane. All the points are dis ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- Number of Parallelograms(求平行四边形个数)
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- D. Number of Parallelograms
D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...
- D. Number of Parallelograms 解析(幾何)
Codeforce 660 D. Number of Parallelograms 解析(幾何) 今天我們來看看CF660D 題目連結 題目 給你一些點,求有多少個平行四邊形. 前言 @copyrig ...
- CodeForces 660D Number of Parallelograms
枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...
随机推荐
- JSF教程(8)——生命周期之Apply Request Values Phase
当一个组件树在一个postbacks请求中被恢复之后其中每一个组件从request的參数中取得各自的值,这里使用的是processDecodes方法. 这个值会保存在本地的每一个组件中,在源代码中此过 ...
- Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号
Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号 1. dwr的长处相对于ajax来说.. 1 2. DWR工作原理 1 3. Dwr的架构 2 4. 自己 ...
- Attribute "resultType" must be declared for element type "insert".
这是mybatis插入数据库之后出现的问题,至于为什么出现这个问题,是因为插入的时候你照抄了查询的语句,插入的时候只有id属性和parameterType属性,并没有“resultType”属性,要注 ...
- python etree解析xml
# -*- coding:utf-8 -*- #conding:utf-8 __author__ = 'hdfs' ''' 简洁 高效 明了 ElementTree轻量级的 Python 式的 API ...
- Mac中遇到的Eclipse连接不上mySql的问题
1.首先我们在eclipse中连接数据库的过程中,遇到的问题就是如上图.开始百度Communications link failure 这几个关键字.得到的结果基本上就是基本配置参数wait_time ...
- Hadoop起源
本文来自Doug Cutting为<Hadoop权威指南>所作之序,感觉读一下还是挺有收获的. Hadoop 起源于Nutch项目.我们几个人有一段时间一直在尝试构建一个开源的Web搜索引 ...
- 果园里有一堆苹果,一共n头(n大于1小于9)熊来分,第一头为小东,它把苹果均分n份后,多出了一个,它扔掉了这一个,拿走了自己的一份苹果,接着第二头熊重复这一过程,即先均分n份,扔掉一个然后拿走一份,以此类推直到最后一头熊都是这样(最后一头熊扔掉后可以拿走0个,也算是n份均分)。问最初这堆苹果最少有多少个。
include "stdafx.h" // ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include<iostream> ...
- HDU 5338(ZZX and Permutations-用线段树贪心)
ZZX and Permutations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/O ...
- eclipse maven安装配置
下载在Apache下载Maven,下载地址:http://maven.apache.org/download.html,在win7下载文件为:apache-maven-3.1.0-bin.zip. ...
- Linux系统初始化流程
POST-->BIOS(Boot Sequence)-->MBR(bootloader)-->Kernel(initrd)-->/sbin/init(/etc/inittab) ...