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

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, contains2 space-separated integers x 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

- -

Sample Output
Case :
Case : 6

题目链接:http://lightoj.com/volume_showproblem.php?problem=1058

*******************************************************

题意:给出T组实例,每组实例给出n各个点的坐标,判断能后成多少个平行四边形。

分析:使用向量法判断,只要满足x1+x3=x2+x4,y1+y3=y2+y4,则说明可以构成平行四边行

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 1200 struct node
{
int x,y;
}p[N]; node q[]; bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
} int main()
{
int T ,kk=,i,j,n; scanf("%d", &T); while(T--)
{
scanf("%d", &n); for(i=;i<n;i++)
scanf("%d%d", &p[i].x,&p[i].y); int u=;
for(i=;i<n-;i++)///保存好向量判断要用到的值
{
for(j=i+;j<n;j++)
{
q[u].x=p[i].x+p[j].x;
q[u++].y=p[i].y+p[j].y;
}
} sort(q,q+u,cmp); int ans=,f=,sum=;
for(i=;i<u;i++)///使用向量法判定是否满足为平行四边形
{
if(q[i].x==q[f].x&&q[i].y==q[f].y)
sum++;
else
{
f=i;///
ans+=sum*(sum-)/;///可以构成平行四边形的数目
sum=;
}
} printf("Case %d: %d\n",kk++,ans);
}
return ;
}

附上一个RE的代码:(使用的斜率和b值判断的)指出一些错误和注意事项

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 12000
#define INF 0x3f3f3f3f struct node
{
int x,y;
}p[N]; struct no
{
double k,l,b;
}q[N];///应为q[500000],对于储存统计比较条件的这个数组一定要开的更大,依旧为N的话RE无止境。。。 double Len(node a,node b)
{
double x=b.x-a.x;
double y=b.y-a.y;
double len=sqrt(x*x+y*y);
return len;
} int main()
{
int T ,kk=,i,j,n; scanf("%d", &T); while(T--)
{
scanf("%d", &n); memset(p,,sizeof(p));
memset(q,,sizeof(q)); for(i=;i<n;i++)
scanf("%d%d", &p[i].x,&p[i].y); int u=;
for(i=;i<n-;i++)
{
for(j=i+;j<n;j++)
{
if(p[j].x-p[i].x!=)
{
q[u].k=1.0*(p[j].y-p[i].y)/(p[j].x-p[i].x);
q[u].b=p[i].y-q[u].k*p[i].x;
q[u++].l=Len(p[i],p[j]);
}
else
{
q[u].k=INF;
q[u].b=p[i].x;
q[u++].l=Len(p[i],p[j]);
}
}
} int ans=;
for(i=;i<u-;i++)///上面的N改了之后就知道这双重for提交,TLE妥妥的,所以这里思路必须得换一下
{
for(j=i+;j<u;j++)///然后我就直接改方法了,也不知道这个路子能被改出正确答案不%>_<%
{
if((q[i].k==q[j].k)&&(q[i].l==q[j].l)&&q[i].b != q[j].b)
ans++;
}
} printf("Case %d: %d\n",kk++,ans/);///这里显然也天真了
}
return ;
}

Light OJ - 1058 Parallelogram Counting(判定平行四边形)的更多相关文章

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

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

  2. 1058 - Parallelogram Counting 计算几何

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

  3. LightOJ 1058 - Parallelogram Counting 几何思维

    http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...

  4. light oj 1148 - Mad Counting

    1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...

  5. LightOJ - 1058 - Parallelogram Counting(数学,计算几何)

    链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by t ...

  6. Light OJ 1058

    题意: 简单的就组合数 C(m,n): 数据多,大, 要预处理: #include<bits/stdc++.h> using namespace std; typedef long lon ...

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

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

  8. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  9. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

随机推荐

  1. 将MyEclipse中的项目导入到Eclipse中报错的解决放法

    1.导入项目后,会报红色感叹号, 将项目右键,点击红色框.

  2. Silverlight程序中访问配置文件

    以下代码为本人在一Silverlight程序中访问Web端配置文件的代码: private void GetLoadNeed() { // 项目名称读取配置文件 WebClient wcConfigX ...

  3. JPA基本注解介绍

    一.@Entity •@Entity 标注用于实体类声明语句之前, 指出该Java 类为实体类,将映射到指定的数据库表. 如声明一个实体类 Customer,它将映射到数据库中的 customer 表 ...

  4. 移动UI

    UI设计需要关注:色彩,信息布局,交互流程,用户体验,尺寸等

  5. 把luasocket集成到c++中

    建一个项目pro_test,创建一个运行目录test: 把luasocket/src文件夹中的*.lua拷贝到test/src文件夹中: 把socket.dll,mime.dll,lua5.1.dll ...

  6. python2.7学习记录之四

    1.从raw_input()读取的内容永远以字符串的形式返回,把字符串和整数比较就不会得到期待的结果,必须先用int()把字符串转换为我们想要的整型 2.list增加元素 为 append() 3.d ...

  7. hdu-5794 A Simple Chess(容斥+lucas+dp)

    题目链接: A Simple Chess Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  8. java中list集合的内容,如何使用像数据库中group by形式那样排序

    java中list集合的内容,如何使用像数据库中group by形式那样排序,比如:有一个 List<JavaBean> 他中包含了一些如下的内容JavaBean:name    mone ...

  9. kindle使用参考

    转载链接:http://blog.sina.com.cn/nuanfengjia 今天买的kindle499刚刚到货了,体验略差,还有一个就是无按键,完全不会玩,只能自己慢慢摸索了. [新Kindle ...

  10. Eclipse中配置weka,以及添加算法

    Eclipse中配置weka 1 找到weka的安装位置,寻找weka的压缩文件weka-src.jar,将压缩文件解压,解压出的文件夹weka-src. 2 打开Eclipse,新建Java pro ...