POJ 1791 Parallelogram Counting(求平行四边形数量)
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);
}
}
POJ 1791 Parallelogram Counting(求平行四边形数量)的更多相关文章
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- poj 1144 (Tarjan求割点数量)
题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...
- POJ 1971 Parallelogram Counting
题目链接: http://poj.org/problem?id=1971 题意: 二维空间给n个任意三点不共线的坐标,问这些点能够组成多少个不同的平行四边形. 题解: 使用的平行四边形的判断条件:对角 ...
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- POJ1144 Network 题解 点双连通分量(求割点数量)
题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\) ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- poj 1474 Video Surveillance - 求多边形有没有核
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
- 洛谷 P1451 求细胞数量
题目链接 https://www.luogu.org/problemnew/show/P1451 题目描述 一矩形阵列由数字0到9组成,数字1到9代表细胞,细胞的定义为沿细胞数字上下左右若还是细胞数字 ...
随机推荐
- node.js安装Oracledb指导文档
https://community.oracle.com/docs/DOC-931127
- C语言-字符操作函数
1字符数组的初始化: 1.1 char string={'c','h','i','n','a'} 1.2char string={"china"}或者去掉{}即char strin ...
- DevExpress GridControl 控件二表连动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Git、Github和GitLab的区别及与SVN的比较
个人理解: SVN适合领导啊,大家一起在加班,看你进度什么的,git则不必如此,忙完传上来完活. 一.含义: 百度上这样介绍的: Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效. ...
- 零基础逆向工程22_PE结构06_导入表
导入表结构 typedef struct _IMAGE_IMPORT_DESCRIPTOR { union { DWORD Characteristics; DWORD OriginalFirstTh ...
- 数据结构-List接口-LinkedList类-Set接口-HashSet类-Collection总结
一.数据结构:4种--<需补充> 1.堆栈结构: 特点:LIFO(后进先出);栈的入口/出口都在顶端位置;压栈就是存元素/弹栈就是取元素; 代表类:Stack; 其 ...
- 新项目升级到JFinal3.5之后的改变-着重体验自动依赖注入
最近,JFinal3.5发布,喜大普奔,我也应JBolt用户的需求,将JBolt进行了升级,实现可配置自动注入开启,支持JFinal3.5的项目生成.具体可以看:JBolt升级日志 这等工作做完后,我 ...
- datatables添加长按事件
长按事件 $.fn.longPress = function (fn) { var timeout = undefined; var $this = this; for (var i = 0; i & ...
- Jquery ajax中表单提交被拦截的问题处理方法
在实际开发项目中,由于要做支付宝的批量退款处理,需要用到ajax中去提交表单数据,项目截图如下: 由于在第二张截图“确认退款”那里需要异步ajax提交数据到服务器处理信息,处理成功后将返回的数据装载到 ...
- js创建弹框(提示框,待确认框)
;;} html,body{text-size-adjust:none;-webkit-text-size-adjust:none;-webkit-user-select:none;} a{color ...