题目链接: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. Mysql 基础2

    创建数据库:     create  database/*条件*/+ text3/*数据库名称*/ 创建数据库  步骤:查询   创建查询  查询编辑器 (写代码) 删除数据库: drop datab ...

  2. EF没有同步更新(转)

    不知道这算不算一个bug,当你新建一个从数据库生成的edmx时,他能正确的生成所有的tt文件,但是当你从数据库更新表结构时,他不能正确的更新tt文件,以建立Model1.edmx为例,在解决方案中展开 ...

  3. 【leetcode】Largest Number ★

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. 在Debian8.3中解决Odoo出现的问题:Unable to find Wkhtmltopdf on this system. The report will be shown in html.

    解决Odoo出现的问题:Unable to find Wkhtmltopdf on this system. The report will be shown in html. 下载wkhtmltop ...

  5. 解决xib约束冲突

    I would recommend to debug and find which constraint is "the one you don't want". Suppose ...

  6. 在VC中创建并调用DLL

    转自:http://express.ruanko.com/ruanko-express_45/technologyexchange6.html 一.DLL简介 1.什么是DLL? 动态链接库英文为DL ...

  7. iphone删除自动更新的系统

    1.利用 etc/host 文件屏蔽 Apple 更新服务器用电脑 iTools 或者手机 iFile 打开 etc/host 文件,添加:127.0.0.1 mesu.apple.com到文件中.2 ...

  8. 赛车比赛(洛谷U4566)

    题目背景 kkk在赛车~ 题目描述 现在有N辆赛车行驶在一条直线跑道(你可以认为跑道无限长)上.它们各自以某种速度匀速前进,如果有两辆车A车和B车,A车在B车的后面,且A车的速度大于B车的速度,那么经 ...

  9. Linux 下根据进程名kill进程

    脚本方式实现: #!/bin/sh #根据进程名杀死进程 if [ $# -lt 1 ] then echo "缺少参数:procedure_name" exit 1 fi PRO ...

  10. 查看局域网内在线的主机ip和mac地址

    ]# nmap -sP Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-12 22:43 CST Nmap scan report for 192. ...