codeforces 660D. Number of Parallelograms
2016-04-09 10:30
357 查看
D. Number of Parallelograms
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
看那些点能组合多少平行四边形,,,,,,
代码:
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
看那些点能组合多少平行四边形,,,,,,
代码:
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct node{ int x,y; }dian[2020]; struct nn{ int xc,xy; }bian[2020000]; bool cm(node xx,node yy) { if (xx.x==yy.x) return xx.y<yy.y; return xx.x<yy.x; } bool cmp(nn xx,nn yy) { if (xx.xc==yy.xc) return xx.xy<yy.xy; return xx.xc<yy.xc; } int main() { int n; int k=0,s,kai,lp; scanf("%d",&n); for (int i=0;i<n;i++) scanf("%d%d",&dian[i].x,&dian[i].y); sort(dian,dian+n,cm); for (int i=0;i<n-1;i++) { for (int j=i+1;j<n;j++) { bian[k].xc=dian[j].x-dian[i].x; bian[k++].xy=dian[j].y-dian[i].y; } } sort(bian,bian+k,cmp); kai=0; s=0; for (int i=1;i<k;i++) { if (bian[i].xc!=bian[i-1].xc||bian[i].xy!=bian[i-1].xy) { lp=i-kai; kai=i; s+=(lp-1)*lp/2; } } printf("%d\n",s/2); return 0; }
相关文章推荐
- redis参数优化
- 需求又改了
- matlab正则表达式
- 贪心算法—— hdu 2037 今年暑假不AC
- django-表单
- NSDateFormatter 相关理解
- Oracle 中TNS的作用
- MySQL 基础(DDL)
- java读取excel的时候,使用getRichStringCellValue()读取到数值类型数据的时候就报错了
- 关于matlab程序打包成exe可执行文件或者jar包的常见问题
- django-视图
- SVN管理工具Cornerstone之:创建分支、提交合并
- 蓝桥杯-基础练习-数列排序
- 人脸识别之线性回归
- Androidi性能优化之多线程和同步
- LeetCode——Combination Sum II
- MySQL 基础(DDL)
- 在MacOS下Python安装lxml报错xmlversion.h not found 报错的解决方案
- django-模板
- Android跳转到应用安装界面的方法