Parallelogram
Counting

刚学hash还不会用,看到5000ms的时限于是想着暴力来一发应该可以过。以前做过类似的题,求平行四边形个数,好像是在CF上做的,但忘了时限是多少了,方法是一样的。

题意:给出n个点坐标,求平面中有多少个平行四边形。

思路:我们知道,平行四边形的条件是两条边平行且相等。我们把每条边分解成x和y方向的向量,只要两条边对应相等就可以了,于是预处理所有的边,然后排序,然后相等的肯定在一起,所以用试探法往前,注意每个平形四边形都被记录了两次,所以答案是总数量除以2。

struct line
{
int x,y,i,j;
} a[N*N];
struct node
{
int x,y;
} p[N];
int cmp(node a,node b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
int cmp1(line a,line b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0; i<n; i++) scanf("%d%d",&p[i].x,&p[i].y);
sort(p,p+n,cmp);
int len=0;
for(int i=0; i<n; i++)
for(int j=n-1; j>i; j--)
{
a[len].i=i,a[len].j=j;
a[len].x=p[j].x-p[i].x,a[len++].y=p[j].y-p[i].y;
}
sort(a,a+len,cmp1);
int ans=0;
for(int i=0; i<len; i++)
{
for(int j=i+1; j<len; j++)
if(a[i].x==a[j].x&&a[i].y==a[j].y)
{
if(a[i].i!=a[j].i&&a[i].i!=a[j].j&&a[i].j!=a[j].i&&a[i].j!=a[j].j)
ans++;
}
else break;//往后没有必要了,不然超时
}
printf("%d\n",ans/2);
}
return 0;
}

POJ 1971-Parallelogram Counting,暴力1063ms!的更多相关文章

  1. POJ 1971 Parallelogram Counting (Hash)

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

  2. POJ 1971 Parallelogram Counting

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

  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 1971 统计平行四边形 HASH

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

  8. poj 2021 Relative Relatives(暴力)

    题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...

  9. poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】

    题目:  http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...

随机推荐

  1. 求矩阵的n次方 c语言实现

    矩阵的n次方,比较容易理解的想法是递归. 思路是这样的,把n分成两部分,当n是偶数的时候,即为左右两边的乘积,如果n是奇数,即为左右两边的乘积再乘a ) matrixn())^*a else matr ...

  2. sql server Cannot resolve the collation conflict between "Chinese_PRC_BIN" and "Chinese_PRC_CI_AS" in the equal to operation

    今天查询二个db,出现这个错误,二种方法,一种是把db里的collation改成一样的:如果不方便可以直接在sql语句后面转一下: select * from table where crm_mscr ...

  3. LeetCode Add and Search Word - Data structure design (trie树)

    题意:实现添加单词和查找单词的作用,即实现字典功能. 思路:'.' 可以代表一个任何小写字母,可能是".abc"或者"a.bc"或者"abc.&quo ...

  4. Python实现1-9数组形成的结果为100的所有运算式

    问题: 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性.例如:1 + 2 + 34–5 + 67–8 + 9 = 100. f ...

  5. Scala 的list

    9.1 使用列表 列表类型:跟数组一样,列表也是同质化的(homogeneous).即所有元素都要是同种类型. 列表结构:所有列表由两部分组成:Nil 和 ::(cons). 基本操作:主要有三个:h ...

  6. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class

    解决方案: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 作用://取消数据库配置 但是 在用到数据库的时候记 ...

  7. CAD交互绘制矩形批注(网页版)

    js中实现代码说明: 动态拖放时的绘制事件: function DynWorldDrawComment2( pCustomEntity,pWorldDraw, curPt) { // 得到绘制参数. ...

  8. faster rcnn需要理解的地方

    http://blog.csdn.net/terrenceyuu/article/details/76228317 https://www.cnblogs.com/houkai/p/6824455.h ...

  9. delphi win7 and high path

    Close DelphiLocate bordbk120N.dll (C:\Program Files (x86)\CodeGear\RAD Studio\6.0\bin)Make a backup ...

  10. WebAssembly MDN简单使用

    MDN 就是通过编译器编译完成c后生成的胶水代码 引入js 就能直接调用定义在c或者c++中的函数了 c代码如下: #include <stdio.h> #include <stdl ...