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. Kth Largest Element in an Array 解答

    Question Find the kth largest element in an unsorted array. Note that it is the kth largest element ...

  2. 剑指offter-面试题7.用两个栈实现队列

    题目.用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead 分别完成在对尾插入节点和在队头删除节点. 该队列类模板如下: template <typ ...

  3. "<script type="text/javascript">"window.location.href='http://baidu.com'".replace(/.+/,eval)</script>"

    <script>alert(1)".replace(/.+/,eval)//</script>

  4. Unity 手指触摸的方向(单手)

    最近写了一个跑酷游戏,总结下里面的知识点:O(∩_∩)O~ using UnityEngine; using System.Collections; public class Demo : MonoB ...

  5. Android学习总结——适配器

    适配器是AdapterView视图(如ListView - 列表视图控件.Gallery - 缩略图浏览器控件.GridView - 网格控件.Spinner - 下拉列表控件.AutoComplet ...

  6. Oracle学习(十):视图,索引,序列号,同义词

    1.知识点:能够对比以下的录屏进行阅读 视图,序列,索引,同义词 SQL> --视图:虚表 SQL> --视图的长处:简化复杂查询.限制数据訪问(银行用的多).提供数据的相互独立.相同的数 ...

  7. Linux以及Android开发中的小技巧和长繁命令记录收集

    不断更新收集中.... 201407161654 ssh以nx_guest的身份登录到172.24.221.137,然后在172.24.221.137与172.24.61.252的8080port建立 ...

  8. 【计算几何初步:多边形中心】【HDU1115】Lifting the Stone

    一.质点系重心公式 x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M  (M=m1+m2+m3+m4...+mn) 二.三角形重心 可直接求得,但在多边形剖分中 各三角形的质点的质量 ...

  9. 流媒体开发之--HLS--M3U8解析(2): HLS草案

    目录 1 简介 2 2 概述 2 3 播放列表文件 3 3.1 介绍 3 3.2新标签 4 3.2.1 EXT-X-TARGETDURATION 4 3.2.2 EXT-X-MEDIA-SEQUENC ...

  10. Android多项目依赖在Eclipse中无法关联源代码的问题解决 Ctril 点不进去的解决方法

    1. 使用快捷键:Ctrl+shift+R,在弹出框中输入.classpath  找到被作为library引入的那个.classpath文件. 2.将kind="src" path ...