POJ 1971 Parallelogram Counting【平面几何】
2016-03-07 21:30
302 查看
Parallelogram Counting
Description
There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets of these points that can be written as {A, B, C, D} such
that AB || CD, and BC || AD. No four points are in a straight line.
Input
The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases. It is followed by the input data for each test case.
The first line of each test case contains an integer n (1 <= n <= 1000). Each of the next n lines, contains 2 space-separated integers x and y (the coordinates of a point) with magnitude (absolute value) of no more than 1000000000.
Output
Output should contain t lines.
Line i contains an integer showing the number of the parallelograms as described above for test case i.
Sample Input
Sample Output
恩,题意大致是,给出平面上n个点的坐标,求这些坐标能构成多少个平行四边形。开始看的用向量做,总是WA也找不到哪错,向量相等且不在一条直线上的向量的对数除2不就是结果?又用的中点做,中点相同的两条线段一定可以组成一平行四边形。
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 6073 | Accepted: 2072 |
There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets of these points that can be written as {A, B, C, D} such
that AB || CD, and BC || AD. No four points are in a straight line.
Input
The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases. It is followed by the input data for each test case.
The first line of each test case contains an integer n (1 <= n <= 1000). Each of the next n lines, contains 2 space-separated integers x and y (the coordinates of a point) with magnitude (absolute value) of no more than 1000000000.
Output
Output should contain t lines.
Line i contains an integer showing the number of the parallelograms as described above for test case i.
Sample Input
2 6 0 0 2 0 4 0 1 1 3 1 5 1 7 -2 -1 8 9 5 7 1 1 4 8 2 0 9 8
Sample Output
5 6
恩,题意大致是,给出平面上n个点的坐标,求这些坐标能构成多少个平行四边形。开始看的用向量做,总是WA也找不到哪错,向量相等且不在一条直线上的向量的对数除2不就是结果?又用的中点做,中点相同的两条线段一定可以组成一平行四边形。
#include <iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define maxn 1010 using namespace std; struct Node { int x,y; }; struct Edge { int a,b; Node e; }; bool cmp(Edge a,Edge b) { if(a.e.x==b.e.x) return a.e.y<b.e.y; return a.e.x<b.e.x; } Edge edge[maxn*maxn/2]; Node node[maxn]; int main() { int T,n; scanf("%d",&T); for(int t=1;t<=T;++t) { scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d%d",&node[i].x,&node[i].y); int k=0; for(int i=0;i<n-1;++i) { for(int j=i+1;j<n;++j) { edge[k].a=i; edge[k].b=j; edge[k].e.x=(node[i].x+node[j].x); edge[k].e.y=(node[i].y+node[j].y); k++; } } sort(edge,edge+k,cmp); int ans=0; for(int i=0;i<k;++i) { int j=i; int num=0; while(j<k&&edge[j].e.x==edge[i].e.x&&edge[j].e.y==edge[i].e.y) { j++; num++; } ans+=num*(num-1)/2; i=j-1; } printf("%d\n",ans); } return 0; }
相关文章推荐
- 静态static
- Java命名规范
- 【nova】liberty版本openstack在线调整云主机大小
- Git创建本地版本仓库
- CXX0025: 错误: 运算符要求类/结构/联合
- java类加载器
- js下载文件
- 算法竞赛入门经典 习题2-10 排列(permutation)
- 前端面试准备1----JS中eval()解析和为什么不要使用eval
- 第一次做架构师的要考虑的地方
- XML简介及解析
- yum下载rpm包到本地
- 扩展lv
- Java面试题搜罗
- BZOJ_P2820 YY的GCD(数论+莫比乌斯反演)
- pat1012:数字分类
- Java HashMap And PriorityQueue Use
- UVa1586
- 图像特征提取理论
- 蓝桥杯练习系统历届试题 剪格子 dfs