1058 - Parallelogram Counting
Time Limit: 2 second(s) Memory Limit: 32 MB

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 integersx 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

Output for 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

Case 1: 5

Case 2: 6

题解:

给一系列点,让找到可以组成的平行四边形的个数;

思路:由于平行四边形的交点是唯一的,那么我们只要记录每两个直线的交点,判断交点重复的个数可以求出来了;假设有这个交点有三个重复的,则ans+=3*2/2;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long LL;
const int MAXN=;
struct Dot{
double x,y;
bool operator < (const Dot &b) const{
if(x!=b.x)return x<b.x;
else return y<b.y;
}
};
Dot dt[MAXN];
Dot num[MAXN*MAXN];
int main(){
int T,N,kase=;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i=;i<N;i++)scanf("%lf%lf",&dt[i].x,&dt[i].y);
int tp=;
for(int i=;i<N;i++)
for(int j=i+;j<N;j++){
if(dt[i].x==dt[j].x&&dt[i].y==dt[j].y)continue;
num[tp].y=(dt[i].y+dt[j].y)/;
num[tp].x=(dt[i].x+dt[j].x)/;
tp++;
}
sort(num,num+tp);
LL ans=,cur=;
for(int i=;i<tp;i++){
if(num[i].x==num[i-].x&&num[i].y==num[i-].y)cur++;
else{
ans+=cur*(cur-)/;cur=;
}
}
printf("Case %d: %lld\n",++kase,ans);
}
return ;
}

Parallelogram Counting(平行四边形个数,思维转化)的更多相关文章

  1. 计算几何 + 统计 --- Parallelogram Counting

    Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5749   Accepted: ...

  2. 1058 - Parallelogram Counting 计算几何

    1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...

  3. POJ 1971 Parallelogram Counting (Hash)

          Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6895   Acc ...

  4. LightOJ 1058 - Parallelogram Counting 几何思维

    http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...

  5. Light OJ - 1058 Parallelogram Counting(判定平行四边形)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  6. POJ 1791 Parallelogram Counting(求平行四边形数量)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  7. 简单题思维转化BestCoder

    题意:给你a, b, c, d四个数,这几个数的范围都是大于0小于1000的整数,让比较 a ^b 和 c ^ d的大小. 这道题看着特别简单,但是当时就是做不出来,将近一个月没有做题了,手生了,不过 ...

  8. Codeforces 911D. Inversion Counting (数学、思维)

    题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...

  9. Number of Parallelograms(求平行四边形个数)

    Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. [Ext JS 4] 实战之多选下拉单 (带checkbox)

    前言 Ext js 创建一个多选下拉单的方式很简单, 使用Ext.form.ComboBox, 设置 multiSelect 为true 就可以了. 但是如果要在每个下拉之前加上一个checkbox, ...

  2. log4net 使用与配置 每天一份log文件

    1.下载 或 在nuget安装 log4net 2. web.config (app.config) <configuration> <configSections> < ...

  3. Ubuntu 系统搭建php服务器 用ssh 远程操作

    一:在桌面下载xshell客户端连接 ,vmavar 上的 Ubuntu系统,遇到的问题跟大家分享一下,希望大家少走弯路 Ubuntu系统默认没有ssh server 要安装 apt-get inst ...

  4. .NETFramework类库

    .NET Framework 包括可加快和优化开发过程并提供对系统功能的访问的类.接口和值类型. 为了便于语言之间进行交互操作,大多数 .NET Framework 类型都符合 CLS,因而可在编译器 ...

  5. CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)(转载)

    在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾斜.移动这四种类型的变形处理,本文将对此做详细介绍. 一.旋转 rotate 用法:transform: rotate(45 ...

  6. 读取本地文件理解FileReader对象的方法和事件以及上传按钮的美化。

    一.FileReader对象 用来把文件读入内存,并且读取文件中的数据.FileReader对象提供了异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据. 浏览器支持情况, ...

  7. c# 面相对象3-之继承性

    继承:类与类之间的关系(父子关系) 子类继承父类,那么子类就拥有父类的公共属性和方法一个子类只能继承一个父类,一个父类可以有好多子类子类对象可以直接转成父类,但父类只能转回对应的子类如果子类转成父类之 ...

  8. iOS FMDB

    FMDB FMDB概述 什么是FMDB * FMDB是iOS平台的SQLite数据库框架 * FMDB以OC的方式封装了SQLite的C语言API FMDB的优点 * 使用起来更加面向对象,省去了很多 ...

  9. WCF如何在浏览器访问

    1.新建wcf服务看到有如下两个方法,在浏览器调用框中的方法.

  10. HDU 1057 - A New Growth Industry

    简单的模拟. 给定天数n,给定D[0]~D[15]给定一个20*20的矩阵.每个格子内有一个0~3的数字,表示细菌数.每天,每个格子将加上D[k],k表示这个格子以及上下左右相邻格子的细菌之和(矩阵外 ...