Parallelogram Counting
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 6895   Accepted: 2423

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

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases. It is followed by the input data for each test case. 
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

Output should contain t lines. 
Line i contains an integer showing the number of the parallelograms as described above for test case i. 

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

5
6 思路:
没有思路。
暴力:TLE
hash:TLE
直接怀疑人生。
在此之间,我甚至怀疑了POJ是不是卡了我的map,后来改成模拟链表。。。。TLE!!
我。。。。。
TLE代码之一:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef unsigned long long ll;
const int maxn = 1024;
ll x[maxn],y[maxn];
ll state[1000086];
int head[maxn];
int num[maxn],Next[1000086];
int main()
{
int n,T;
ll sd;
scanf("%d",&T);
while(T--){
int ans=0;
scanf("%d",&n);
memset(head,-1,sizeof(head));
int t=0;
for(int i=1;i<=n;i++){
scanf("%lld%lld",&x[i],&y[i]);
for(int j=1;j<i;j++){
sd=(x[i]+x[j])*10000009+y[i]+y[j];
int h=sd%maxn;
for(int k=head[h];k!=-1;k=Next[k]){
if(state[k]==sd){ans++;}
}
t++;
state[t]=sd;
Next[t]=head[h];
head[h]=t;
}
}
printf("%d\n",ans);
}
}

  

 

POJ 1971 Parallelogram Counting (Hash)的更多相关文章

  1. POJ 1971 Parallelogram Counting

    题目链接: http://poj.org/problem?id=1971 题意: 二维空间给n个任意三点不共线的坐标,问这些点能够组成多少个不同的平行四边形. 题解: 使用的平行四边形的判断条件:对角 ...

  2. POJ 1971 统计平行四边形 HASH

    题目链接:http://poj.org/problem?id=1971 题意:给定n个坐标.问有多少种方法可以组成平行四边形.题目保证不会有4个点共线的情况. 思路:可以发现平行四边形的一个特点,就是 ...

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

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

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

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

  5. Parallelogram Counting(平行四边形个数,思维转化)

    1058 - Parallelogram Counting    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...

  6. 1058 - Parallelogram Counting 计算几何

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

  7. POJ 2002 统计正方形 HASH

    题目链接:http://poj.org/problem?id=2002 题意:给定n个点,问有多少种方法可以组成正方形. 思路:我们可以根据两个点求出对应正方形[有2个一个在两点左边,一个在两点右边] ...

  8. POJ 3320 (尺取法+Hash)

    题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的, ...

  9. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

随机推荐

  1. 在delphi中生成GUID

    什么是 GUID ? 全球唯一标识符 (GUID) 是一个字母数字标识符,用于指示产品的唯一性安装.在许多流行软件应用程序(例如 Web 浏览器和媒体播放器)中,都使用 GUID. GUID 的格式为 ...

  2. Spring validator常用注解

    规则: 原版在这里 https://www.cnblogs.com/wjh123/p/8745473.html @AssertFalse Boolean,boolean 验证注解的元素值是false ...

  3. 前端传递给后端且通过cookie方式,尽量传递id

    前端传递给后端且通过cookie方式,尽量传递id

  4. Js 布尔值操作符

    在js中,逻辑与(&&) 和 逻辑或(||)可以对任意的数据类型进行操作,而在高级程序设计中只给出了一系列的规则,并没有进行解释,所以经常记不住.在读其它书籍的时候,读到了它的原理,其 ...

  5. codeforces231C

    To Add or Not to Add CodeForces - 231C A piece of paper contains an array of n integers a1, a2, ..., ...

  6. codeforces467C

    George and Job CodeForces - 467C The new ITone 6 has been released recently and George got really ke ...

  7. luogu3702-[SDOI2017]序列计数

    Description Alice想要得到一个长度为nn的序列,序列中的数都是不超过mm的正整数,而且这nn个数的和是pp的倍数. Alice还希望,这nn个数中,至少有一个数是质数. Alice想知 ...

  8. Root test & Ratio test

    几何级数(Geometric Series/Geometric Progression) Root test与Ratio test都依赖于几何级数求和理论,因此这里先讨论该理论. 在数学上,几何级数, ...

  9. SpringMVC 复杂对象数据绑定

    表单在 web 页面上无处不在,有些表单可能很复杂,大部分表单里的输入项都会对应后端对象属性.SpringMVC 可以自动将表单值绑定到对象上!而且能绑定很复杂的对象!!这里就不写那些基本的表单绑定了 ...

  10. shelve 模块

    shelve 模块概述:   shelve是python的自带model.   可以直接通过import shelve来引用.   shelve类似于一个存储持久化对象的持久化字典,即字典文件.   ...