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 ...
随机推荐
- Java使用笔记之stream和sorted使用
//对象类型stream排序List<User> users = new ArrayList<User>(){ { add(new User("a", &q ...
- Linux 查看.so中导出函数
方法一 nm -D **.so 但这样能看到所有的导出,乱七八糟的很多,筛选用: nm **.so | grep XX 方法二objdump -tT **.so
- Java NIO之Charset类字符编码对象
介绍 java中使用Charset来表示编码对象 This class defines methods for creating decoders and encoders and for retri ...
- 网络工具的瑞士军刀netcat
这是一个聒噪的夜晚,假设要给出个原因.可能是由于尽管我认为西班牙不纯粹,可是怎么也不至于干为人家搭台面自己不唱戏的角色吧..结束以后.我认为该玩一下素有网络瑞士军刀之称谓的netcat了. 尽管瑞士军 ...
- Spark源码分析之六:Task调度(二)
话说在<Spark源码分析之五:Task调度(一)>一文中,我们对Task调度分析到了DriverEndpoint的makeOffers()方法.这个方法针对接收到的ReviveOffer ...
- NuGet管理工具安装
安装完成后VS重启即可
- Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现
看到cocos2d-x推出了3.1版本号,真是每月一次新版本号,速度. 另一个好消息就是http://cn.cocos2d-x.org/上线了,祝贺!啥时候把我的视频和教程放上去呢?!! . 视频下载 ...
- js中scrollLeft、scrollWidth、offsetTop等相关位置属性的理解(转)
1.常见的事件位置属性 e.pageX——相对整个页面的坐标 注意:IE6.IE7.IE8无该属性 e.layerX——相对当前坐标系的border左上角开始的坐标 注意:在opera.IE6.IE7 ...
- Unix环境高级编程—进程控制(二)
一.函数wait和waitpid 今天我们继续通过昨天那个死爹死儿子的故事来讲(便于记忆),现在看看wait和waitpid函数. #include<sys/wait.h> pid_t w ...
- OpenFileDialog对话框Filter属性(转)
OpenFileDialog对话框的Filter属性说明: 首先说明一个示例,分析一下Filter属性的构成:“ Excel文件|*.xls ”,前面的“Excel文件”成为标签,是一个可读的字符串, ...