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

给出点的坐标求出能连成平行四边形的数量。

思路:

  用结构体记录每两个点的x坐标和与y坐标和( 相当于记录这两个点为对角线的情况 )然后循环判断多少个对角线的被交点平分(结构体中x,y的值相等)求出对角线的数量,然后C(sum,2)。

 #include<cstdio>
#include<algorithm>
using namespace std;
int x[],y[];
struct stu
{
int x,y;
}st[*/];
bool cmp(stu a,stu b)
{
if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
}
int main()
{
int t,ss=;
scanf("%d",&t);
while(t--)
{
int n,i,j;
scanf("%d",&n);
for(i = ; i < n ; i++)
{
scanf("%d %d",&x[i],&y[i]);
}
int k=;
for(i = ; i < n ; i++)
{
for(j = i+ ; j < n ; j++)
{
st[k].x=x[i]+x[j];
st[k++].y=y[i]+y[j];
}
}
sort(st,st+k,cmp);
int num=,sum=,ans=;
for(i = ; i < k ; i++)
{
if(st[num].x == st[i].x && st[num].y == st[i].y)
sum++; //sum代表线的数量
else
{
ans+=(sum*(sum-)/); //这里是C(sum,2)
num=i;
sum=; }
}
printf("Case %d: %d\n",++ss,ans);
}
}

最新文章

  1. # ios开发 @property 和 Ivar 的区别
  2. WebAPI接口返回ArrayList包含Dictionary对象正确解析
  3. JAVA常见面试题之Forward和Redirect的区别
  4. HTML5横竖屏提示
  5. 关于jq ajax封装以及error的报错参数
  6. PHP替代正则匹配的高效函数
  7. iOS开发UI篇—实现一个私人通讯录小应用【转】
  8. 武汉科技大学ACM :1002: 零起点学算法66——反话连篇
  9. 给一组a标签当前页a标签加class
  10. sql server varchar(10)和 nvarchar(10)存储数据长度
  11. 14.2.5.4 Physical Structure of an InnoDB Index InnoDB Index 的物理结构
  12. SpringBoot实践 - SpringBoot+MySql+Redis
  13. tensorflow中使用Batch Normalization
  14. UI5-文档-4.25-Sorting and Grouping
  15. POI导出excel,本地测试没问题,linux测试无法导出
  16. 转【Zabbix性能调优:配置优化】
  17. [转]Android Message.obtain() 和Handler.obtainMessage()的区别
  18. 最简易的PHP Storm调试模式开启方式
  19. 无比迅速敏捷地开发iOS超精美控件
  20. Lucio: We avoided Mourinho after every loss

热门文章

  1. 使用xadmin覆盖Django的admin
  2. 跟老男孩学Linx运维---web集群实战笔记
  3. CentOS 6.4 中yum命令安装php5.2.17
  4. 浅析libuv源码-node事件轮询解析(3)
  5. 切记切记:Spring配置文件中,Component-scan无法扫描到的类中的自动装配对象无法被调用,报空指针错误。
  6. jquery显示隐藏效果
  7. ComboBox控件“设置 DataSource 属性后无法修改项集合”的解决【转】
  8. 【Python图像特征的音乐序列生成】GitHub已经有人将mingus改到了Python3版本
  9. Android(java)学习笔记114:Service生命周期
  10. python之道10