Lightoj 1058 (组合数学)
2016-08-13 21:53
423 查看
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
Input starts with an integer T (≤ 15), denoting the number of test cases.
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
For each case, print the case number and the number of parallelograms that can be formed.
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
Case 1: 5
Case 2: 6
还是得窃取别人的智慧
对于一个平行四边形啦,它们对角线的中点相交诶,所以说,只需要判断一下是否存在两条线中点相同就好了,然后结果就所以取两条线就过了
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
Input starts with an integer T (≤ 15), denoting the number of test cases.
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
For each case, print the case number and the number of parallelograms that can be formed.
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
Case 1: 5
Case 2: 6
还是得窃取别人的智慧
对于一个平行四边形啦,它们对角线的中点相交诶,所以说,只需要判断一下是否存在两条线中点相同就好了,然后结果就所以取两条线就过了
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; #define M 1010 #define LL long long bool vis[M][M]; struct node { double x, y; }; node no[M*M/2]; bool cmp(node a, node b) { if(a.x == b.x) { return a.y<b.y; } return a.x < b.x; } int main() { int t, n; double x[M], y[M]; scanf("%d", &t); for(int ca=1; ca<=t; ca++) { scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%lf%lf", &x[i], &y[i]); } int k = 0; for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { no[k].x = x[i] + x[j]; no[k++].y = y[i] + y[j]; } } sort(no, no+k, cmp);//方便找出相同的点诶 int flag = 0, num = 1, ans = 0; for(int i=1; i<k; i++) { if(no[i].x == no[flag].x && no[i].y == no[flag].y) { num++; } else { ans += num * (num-1) / 2; num = 1; flag = i; } } printf("Case %d: %d\n", ca, ans); } return 0; }
相关文章推荐
- LIGHTOJ 1005(组合数学)
- 【唯一分解定理 && 状态压缩 && 组合数学】LightOJ - 1236 Pairs Forming LCM
- 【LightOJ - 1005 】 Rooks 【组合数学】 4000
- LightOJ 1005 Rooks 动态规划dp || 组合数学
- LightOJ 1005 - Rooks (组合数学dp模拟)
- LightOJ 1005 (数学组合问题)
- lightoj 1005 - Rooks 【组合数学】
- Lightoj 1005 组合数学啊。。。怎么是DP
- lightoj 1005 - Rooks(组合数学)
- LightOJ 1102 Problem Makes Problem(组合数学)
- LightOJ 1005 - Rooks(组合数学解法,记忆化解法)
- lightoj 1005 - Rooks 【组合数学】
- LightOJ 1005 - Rooks (dp、组合数学)
- LightOJ 题目1058Parallelogram Counting(组合数学)
- LightOJ1005---Rooks(简单组合数学)
- lightoj 1095 - Arrange the Numbers 组合数学
- LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数
- lightoj 1060 - nth Permutation 组合数学
- lightOJ1005 组合数学
- LightOJ 1058 Parallelogram Counting(数学)