Codeforces--660D--Number of Parallelograms(几何性质)(组合数)
来源:互联网 发布:资料恢复软件 编辑:程序博客网 时间:2024/06/06 02:02
Number of Parallelograms
Time Limit: 4000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u
Description
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.
Sample Input
Input
40 11 01 12 0
Output
1
Source
Educational Codeforces Round 11
给出n个点的坐标,问你这些点可以组成多少个平行四边形,数据很大,判断平行边肯定是不可以的,会超时,平行四边形有一个性质,对角线互相平分,我们可以得到所有线段的中点,然后判断这些中点重合的有多少,一个中点代表两个给定点,所以每一对中点就可以表示一个平行四边形,判重的时候只需要一个for不会超时
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct node{double x,y;}p[2010],q[4000000+10];int cmp(node s1,node s2){if(s1.x==s2.x)return s1.y<s2.y;return s1.x<s2.x;}int main(){int n;while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);sort(p,p+n,cmp);int cnt=0;for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){q[cnt].x=(p[i].x+p[j].x)/2;q[cnt++].y=(p[i].y+p[j].y)/2;}}sort(q,q+cnt,cmp);__int64 sum=0,cout=0;node s=q[0];for(int i=0;i<cnt;i++){if(abs(s.x-q[i].x)<1e-6&&abs(s.y-q[i].y)<1e-6)cout++;else{if(cout>=1)sum+=cout*(cout-1)/2;cout=1;s=q[i];}}printf("%I64d\n",sum);}return 0;}
0 0
- Codeforces--660D--Number of Parallelograms(几何性质)(组合数)
- CodeForces - 660D Number of Parallelograms (数学几何)给出n个点问能组成的平行四边形个数
- CodeForces 660D Number of Parallelograms(水题)
- codeforces 660D. Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- Codeforces 660D Number of Parallelograms
- Codeforces 660D Number of Parallelograms 【思维】
- CodeForces 660D Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- CodeForces 660D. Number of Parallelograms【模拟】
- codeforces 660D - Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- Codeforces 660D Number of Parallelograms【平行四边形个数】
- Number of Parallelograms CodeForces 660D 思维题
- CodeForces 660D Number of Parallelograms [想法题]
- D. Number of Parallelograms
- D. Number of Parallelograms
- D. Number of Parallelograms
- 使用gridview时,会出现部分item数据显示不出来
- 修改system系统权限
- 循环粉碎文件:Use the find command to execute shred recursively
- diff 命令 expain
- CMT跟踪算法笔记
- Codeforces--660D--Number of Parallelograms(几何性质)(组合数)
- Mac/Linux 查看计算机运行多长时间
- 调用系统方法将文字复制到剪贴板
- imx6 启动流程分析
- web与js的简单交互(朱祈林)
- Node.js 未来会超越 Java 吗?
- MySQL 中清空表的方法
- 【echo】命令的功能是在显示器上显示一段文字,一般起到一个提示作用。
- poj 3185