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 ...
随机推荐
- vs调试,监控变量
- DataTable列 基础处理
DataTable dt=new DataTable(); 新增列: dt.Columns.Add("ColumnsName"); 删除列: dt.Columns.Remove(& ...
- 集团管控的历史读本——Leo鉴书76
当下中国管理咨询界比較火的课题之中的一个就是"集团管控".公司大了之后怎样正好的用人.怎样对下属分公司不失控制.怎样在二代接手之后系统仍然稳固.种种问题都在困扰着企业们.假设我们把 ...
- JOB Hunting 总结-----2013-11-5
从9月份开始的找工作大战,告一段落:其实早在10月中旬就已搞定,现在回想起这过去的几个月,很充实,很疲惫,很挫败又很有成就感! 开始找工作,对未来有过很多憧憬,也很迷茫,不知道自己的未来会在 ...
- 语法之知识点的改进(Func/Action)
上一章我们讲到关于面向对象思想上C#和JAVA之差别.笔者分别从面向对象的三大特性入手.而本章主要讲一些C#改进的知识点.在.NET Framework 2.0之后出现很多新的知识点.这些知识点更是让 ...
- Jquery获取iframe中的元素
iframe与父页面之间相互获取元素的方法: 1.从父页面中获取iframe页面中的元素: 用法: $(window.frames["iframe_include_adverse" ...
- ios --转载获ipa 的图片资源
突然想起当初刚学习iOS的时候,就经常通过抓包和提取素材的方式来模仿App,今天就教大家如何一步步提取App的素材! 大家是否有过想要获取别人的素材的想法?看到某些App的资源很不错,很想导出来用 ...
- Yii2 跨库orm实现
近期在对公司的Yii2项目进行子系统拆分,过度阶段难免会有一些跨库操作,原生语句还好,加下库名前缀就可以了,可是到了orm问题就来了,特别是用到model做查询的时候,现在来记录一下跳过的坑, 像下面 ...
- 在ios中使用单例模式编程
本文转载至 http://blog.csdn.net/remote_roamer/article/details/7107007 1. @implementation Singleton ...
- wamp环境配置;转自发瑞的博客(www.cnblogs.com/cyrfr/p/6483529.html)
php手动搭建环境有好多种组合,版本号不一致,会导致搭建失败. 我搭建的组合是: php5.6+MySQL5.6+Apache2.4的组合. 一.PHP语言包下载 首先从官网上下载php5.6 htt ...