View Code of Problem 1056

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct none{
	int x,y;
}no[10000],n1[1000000];
bool cmp(none x,none y)
{if(x.x!=y.x)
return  x.x<y.x;
else
return x.y<y.y; 
}
int main()
{int t,n,m=1,k;
scanf("%d",&t);
while(t--)
{scanf("%d",&n);
k=0;
for(int i=0;i<n;i++)
scanf("%d%d",&no[i].x,&no[i].y);
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{n1[k].x=no[i].x+no[j].x;
n1[k].y=no[i].y+no[j].y;
k++;
}
sort(n1,n1+k,cmp);
long long ans=0,T=1;
for(int i=1;i<k;i++)
{if(n1[i].x==n1[i-1].x&&n1[i].y==n1[i-1].y)
T++;
else
{ans=ans+T*(T-1)/2;
T=1;
}
}
printf("Case %d: %lld\n",m++,ans);
}}

Double click to view unformatted code.


Back to problem 1056