首页 > 其他分享 >LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数

LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数

时间:2023-05-08 21:32:26浏览次数:51  
标签:个点 1058 LightOJ Parallelogram number points 平行四边形 中点 define


LightOJ - 1058


Parallelogram Counting


Time Limit: 2000MS

Memory Limit: 32768KB

64bit IO Format: %lld & %llu

Submit Status




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

//题意:输入一个n,再输入n个点的坐标。

给你n个点的坐标让你求出这n个点可以组成几个平行四边形。

//思路:

因为平行四边形的两条对角线的交点是唯一的,所以先求出这n个点所能组成的所有线段的中点(n*(n-1)/2个中点),对其进行排序后,对这些中点进行计算,如果在一个中点处有num条线段相交,那么在这个中点处可以组成num*(num-1)/2个平行四边形。最所有中点模拟一遍对其求和即为所得。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
#define N 1010
#define M 1000000007
using namespace std;
struct zz
{
	int x;
	int y;
}p[N],mid[N*N];
int cmp(zz a, zz b)
{
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
int main()
{
	int t,n,i,j,T=1;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%d%d",&p[i].x,&p[i].y);
		//sort(p,p+n,cmp);
		int k=0;
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				mid[k].x=p[j].x+p[i].x;
				mid[k++].y=p[j].y+p[i].y;
			}
		}
		sort(mid,mid+k,cmp);
//		for(i=0;i<k;i++)
//			printf("%d %d-----\n",mid[i].x,mid[i].y);
//		printf("\n");
		int num=1;
		int sum=0;
		for(i=0;i<k-1;i++)
		{
			if(mid[i].x==mid[i+1].x&&mid[i].y==mid[i+1].y)
				num++;
			else 
			{
				sum+=(num*(num-1)/2);
				num=1;
			}
		}
		printf("Case %d: %d\n",T++,sum);
	}
	return 0;
}

 




标签:个点,1058,LightOJ,Parallelogram,number,points,平行四边形,中点,define
From: https://blog.51cto.com/u_16079508/6256252

相关文章

  • XI Samara Regional Intercollegiate Programming Contest Problem J. Parallelogram
    Therearensticks,thei-thofwhichhaslengthai.Alexwantstoassemblefromthemasmanyparallelogramsaspossiblesimultaneously,witheachstickusedatmostinoneparallelogram.Whatmaximalnumberofparallelogramsisitpossibletoassembl......
  • LightOJ1007---Mathematically Hard (欧拉函数)
    Mathematicallysomeproblemslookhard.Butwiththehelpofthecomputer,someproblemscanbeeasilysolvable.Inthisproblem,youwillbegiventwointegersaandb.Youhavetofindthesummationofthescoresofthenumbersfromatob(inclusive).T......
  • LightOJ 1348 Aladdin and the Return Journey (树链剖分)
    树链剖分模板题。最近一直有比赛。。好长时间没写了。明显生疏了。。找个模板题熟悉一下。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>#include......
  • LightOJ - 1044 Palindrome Partitioning(DP)
    题目大意:给你一个字符串,要求你对字符串进行划分,使得划分出来的子串都是回文串,且子串数量达到最小解题思路:用dp[i]表示前i个字符划分成回文串,需要划分成多少个部分接着枚举j,如果[i,j]回文,那么dp[i]=min(dp[i],dp[j-1]+1)#include<cstdio>#include<cstring>#include<al......
  • LightOJ - 1300 Odd Personality(边双连通+奇圈判定)
    题目大意:给出一张无向图,要求找出符合条件的点条件如下:从该点出发,经过一定数量的边,又回到该点,经过的边不能重复经过,且经过的边的数量为奇数解题思路:要回到原点,且不能重复经过边,只能在边双连通分量中找了接着要判断的是有多少个点,只要边双连通分量中有奇圈,那么这个连通分量中的所......
  • LightOJ - 1400 Employment(婚姻稳定问题)
    题目大意:在一个party上,有N个男的,N个女的,要求你将其配对,使其满足1.男生u和女生v还没配对2.他们喜欢对方的程度都大于喜欢各自当前舞伴的程度如果出现了2的情况,他们就会抛下当前的舞伴,另外组成一对解题思路:这题的话,就是婚姻稳定问题,他的解决方法是,男士不断的求婚,而女士不断的拒......
  • LightOJ - 1063 Ant Hills(割点)
    题目大意:求无向图中,有多少个割点解题思路:模版题了#include<cstdio>#include<cstring>#include<vector>#include<stack>usingnamespacestd;#definemax(a,b)((a)>(b)?(a):(b))#definemin(a,b)((a)<(b)?(a):(b))constintMAXNODE=10005;constintM......
  • LightOJ - 1041 Road Construction(最小生成树)
    题目大意:给你N条边,看能否形成最小生成树,如果存在,输出值,不存在,另外输出解题思路:模版题#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<string>#include<iostream>usingnamespacestd;constintMAXNOD......
  • PAT Basic 1058. 选择题
    PATBasic1058.选择题1.题目描述:批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。2.输入格式:输入在第一行给出两个正整数N(≤ 1000)和M(≤ 100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的......
  • HDOJ1058Humble Numbers(丑数)
    HumbleNumbersTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):27739    AcceptedSubmission(s):......