POJ 1971 Parallelogram Counting
来源:互联网 发布:淘宝确认收款是几天 编辑:程序博客网 时间:2024/04/29 20:39
题目:
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.
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.
Line i contains an integer showing the number of the parallelograms as described above for test case i.
Sample Input
260 02 04 01 13 15 17-2 -18 95 71 14 82 09 8
Sample Output
56
这个题目,首先是平行四边形的性质。
A+D=B+C,这里的ABCD可以理解为向量,或者复数。
还可以理解为,关于坐标的线性函数,比如x+y,3x+5y这种。
本题中,为了用不同的整数表示不同的点,我用的是2000000002x+y(因为x和y有正负)
这样的数,大小约为-4*10^18到4*10^18,sum的大小约为-8*10^18到8*10^18
在sum的初始化的时候,我设置为0x7f7f7f7f7f7f7f7f,约为9*10^18,大于sum最大值。
代码:
#include<iostream>#include<algorithm>#include<string.h>using namespace std;long long h=1000000000;long long list[1001];long long sum[1000000];long long x, y;int main(){int t, n;cin >> t;while (t--){cin >> n;for (int i = 0; i < n; i++){cin >> x >> y;list[i] = x*(h * 2 + 2) + y;//点到整数的哈希}memset(sum, 0x80, sizeof(sum));for (int i = 0; i < n; i++)for (int j = i+1; j < n; j++)sum[i*n + j] = list[i] + list[j];//数组选2个数求和的哈希sort(sum, sum + n*n);int ii = 0;while (sum[ii] == 0x8080808080808080)ii++;int num = 0, sumnum = 0;for (; ii < n*n; ii++){if (sum[ii] == sum[ii - 1])num++;else{sumnum += num*(num + 1) / 2;num = 0;}}cout << sumnum << endl;}return 0;}
1 0
- poj 1971 Parallelogram Counting
- POJ 1971 Parallelogram Counting
- POJ 1971 Parallelogram Counting
- poj 1971 Parallelogram Counting
- POJ 1971 Parallelogram Counting
- poj 1971 Parallelogram Counting
- POJ 1971 Parallelogram Counting
- poj 1971 Parallelogram Counting(数学题)
- POJ 1971 Parallelogram Counting【平面几何】
- POJ-----1971Parallelogram Counting数学题
- Parallelogram Counting(POJ 1971)
- POJ 1971 Parallelogram Counting 笔记
- POJ 1971 Parallelogram Counting 解题报告
- POJ 1971 Parallelogram Counting(枚举+HASH)
- LightOJ 1058 & Poj 1971 Parallelogram Counting
- POJ 1971 Parallelogram Counting (Hash)
- poj 1971 Parallelogram Counting 排序 + 计数
- POJ 1971 Parallelogram Counting(hash)
- 音频电源动态管理--概述
- Android MVP架构的自述
- 将IDEA maven项目中src源代码下的xml等资源文件编译进classes文件夹
- 未能加载程序集"Microsoft.Data.Edm"
- iOS 报错:process launch failed: failed to get the task for process XXXX
- POJ 1971 Parallelogram Counting
- 冲突域和广播域的区别
- 字符串或列表反序
- 冒泡排序
- 内存管理器(二十三) 标记-复制式 回收算法
- CoordinatorLayout与滚动的处理
- 迭代器
- 彻底理解android中的内部存储与外部存储
- range xrange