题目链接:http://poj.org/problem?id=1971

题意:给定n个坐标。问有多少种方法可以组成平行四边形。题目保证不会有4个点共线的情况。

思路:可以发现平行四边形的一个特点,就是对角线相交后得到的点。如果两点线的中点相交,那么这两条线就可以组成一个平行四边形[不需去排除4点共线],所以枚举两两组合的点对HASH成中点。然后判断所有中点,如果某个中点出现了K次,那么可以组成K*(K-1)/2个平行四边形。 用map来判断某个中点出现次数会TLE,所以可以对中点进行排序后判重复次数。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long int LL;
typedef unsigned int uint;
#define mp(x,y) make_pair(x,y)
const int MAXN=+;
struct Point{
double x,y;
Point(double a=,double b=):x(a),y(b){};
};
Point P[MAXN],MP[MAXN*MAXN];
Point MidP(Point a,Point b){
return Point((a.x+b.x)/,(a.y+b.y)/);
}
bool cmp(Point a,Point b){
if(a.x==b.x){
return a.y<b.y;
}
return a.x<b.x;
}
int main(){
#ifdef kirito
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n,t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int ans=,cnt=;
for(int i=;i<n;i++){
scanf("%lf %lf",&P[i].x,&P[i].y);
}
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
Point midP=MidP(P[i],P[j]);
MP[cnt++]=midP;
}
}
sort(MP,MP+cnt,cmp);
int idx=,tmp=;
for(int i=;i<cnt;i++){
if(MP[i].x==MP[idx].x&&MP[i].y==MP[idx].y){
tmp++;
}
else{
ans+=tmp*(tmp-)/;
idx=i; tmp=;
}
}
ans+=tmp*(tmp-)/;
printf("%d\n",ans);
}
return ;
}

POJ 1971 统计平行四边形 HASH的更多相关文章

  1. POJ 2002 统计正方形 HASH

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

  2. POJ 1971 Parallelogram Counting (Hash)

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

  3. POJ 1971 Parallelogram Counting

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

  4. POJ 3320 (尺取法+Hash)

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

  5. poj 2408 Anagram Groups(hash)

    id=2408" target="_blank" style="">题目链接:poj 2408 Anagram Groups 题目大意:给定若干 ...

  6. 最新电Call记录统计-full hash join用法

    declare @time datetime set @time='2016-07-01' --最新的电Call记录统计查询--SELECT t.zuoxi1,t.PhoneCount,t.Phone ...

  7. poj 1840 Eqs (hash)

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

  8. POJ 3865 - Database 字符串hash

    [题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...

  9. poj 1200 Crazy Search(hash)

    题目链接:http://poj.org/problem?id=1200 思路分析:从数据来看,该题目使用线性时间算法,可见子串的比较是不可能的:使用hash可以在常数时间内查找,可以常数时间内判重, ...

随机推荐

  1. 关于定时器 setTimeout

    1.这里不考虑线程问题.把javascript想象成在时间线上运行,页面载入时,首先执行的是<script>标签中的代码,之后,将执行更多代码,当进程空闲时,下个代码就被触发并执行 如图: ...

  2. Redis事件管理(三)

    Redis的事件管理和定时器的管理都是自己来实现的,Redis的事件管理分为两部分,一部分是封装了系统的异步事件API,还有一部分是在这基础上封装了一个通用的事件管理器,根据具体的系统来决定具体使用哪 ...

  3. chaper3_exerise_Uva1568_Molar_Mass_分子量

    #include<iostream> #include<iomanip> #include<string> #include<cctype> using ...

  4. vector 去重复

    ①首先将vector排序 sort( vecSrc.begin(), vecSrc.end() ); // 1,2,3,3,4,4,6,7,8,9 ②然后使用unique算法,unique返回值是重复 ...

  5. db2 Hidden columns

    When a table column is defined with the implicitly hidden attribute, that column is unavailable unle ...

  6. JavaScript基础——定义变量

    在JavaScript中使用变量来临时存储和访问来自JavaScript文件的数据.变量既可以指向简单的数据类型,如数字或者字符串:也可以指向更复杂的数据类型,比如对象. 在JavaScript中定义 ...

  7. jq 轮播图

    <style> #focus{width:500px;height:200px;overflow:hidden;/*用一个div把图片包含设置超出范围隐藏*/} </style> ...

  8. sp_who使用

    [SQL Server]  sp_who, sp_who2和sp_who3 sp_who可以返回如下信息: (可选参数LoginName, 或active代表活动会话数)Spid         (系 ...

  9. ASP.NET MVC中Controller返回值类型ActionResult

    1.返回ViewResult视图结果,将视图呈现给网页 public class TestController : Controller { //必须存在Controller\Test\Index.c ...

  10. wifi diplasy流程介绍

    转自:http://blog.csdn.net/dnfchan/article/details/8558552/  另外一篇不错的参考文章:http://www.360doc.com/content/ ...