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代表细胞,细胞的定义为沿细胞数字上下左右若还是细胞数字 ...
随机推荐
- github新手指南
- noip搜索模拟题 骰子
骰子 dice.cpp/c/pas 1s/128M [题目描述] 桌面上有两个特别的骰子.骰子的每一个面,都写了一个不同的数字.设第一个骰子上下左右前后分别为a1, a2, a3, a4, a5, a ...
- Java_面向对象的 static 和 abstract
static:表示静态的 static:可以用来修饰属性.方法.代码块(或初始化块).内部类. 一.static修饰属性(类变量): public class TestStatic { //stati ...
- Java基础:(五)Object通用方法
一.Object对象的九个方法 getClass():hashCode():equals():clone():toString():notify():notifyAll():wait():finali ...
- 【持续更新】Java 字符串相关问题
区别 String s1="xxx" 与 String s2=new String("xxx") 的区别 equals() 和 == 的区别 单引号与双引号的区 ...
- 实例——省市区三级联动 & 还可以输入字符统计
1 省市区三级联动 html代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- 开机报错 the connected AC adapter has a lower wattage than the recommended model which was shipped with the system。
机型:联想Thinkpad T410 报错场景:在电脑插上电源充电情况下开机,会自动进入bios setup utility提示你需要重新设置日期时间.date/time 报错提示:The conne ...
- JavaScirpt 的垃圾(garbage collection)回收机制
一.垃圾回收机制—GC Javascript具有自动垃圾回收机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存. 原理:垃圾收集器会定期(周期性 ...
- jquery解析xml,获取xml标签名
先给一个简单的XML,结构如下 <?xml version="1.0" encoding="uft-8" ?> <msg> <ro ...
- HDFS读写策略
数据的读取过程: 数据读取: 客户端调用FileSystem 实例的open 方法,获得这个文件对应的输入流InputStream. 通过RPC 远程调用NameNode ,获得NameNode 中此 ...