View Code of Problem 1056

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int x,y;
}t[1100],t1[550000];
bool cmp(node a,node b)
{
	if(a.x!=b.x)
	return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int T,n,i,j;
	scanf("%d",&T);
	int cnt=1;
	while(T--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		scanf("%d%d",&t[i].x,&t[i].y);
		int k=0;
		for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++)
		{
			t1[k].x=t[i].x+t[j].x;
			t1[k].y=t[i].y+t[j].y;
			k++;
		}
		sort(t1,t1+k,cmp);
		int l=1;
		int sum=0;
		for(i=1;i<k;i++)
		{
			if(t1[i].x==t1[i-1].x&&t1[i].y==t1[i-1].y)
			{
				l++;
			}
			else
			{
				sum+=l*(l-1)/2;
				l=1;
			}
		}
		printf("Case %d: %d\n",cnt++,sum);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 1056