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. DVWA之Brute Force教程

    ---恢复内容开始--- Brute Force暴力破解模块,是指黑客密码字典,使用穷举的方法猜出用户的口令,是一种广泛的攻击手法. LOW low级别的漏洞利用过程 1.使用burp suite工具 ...

  2. log4sql介绍

    log4sql介绍log4j环境中简单配置的情况下可收集执行的SQL语句和JDBC执行情况,如预编译的”?“显示成参数的实际值 下载log4sql.jar第一步:http://log4sql.sour ...

  3. c#网站对服务器的数据库的备份与还原

    在网站上备份数据库 1.前台页面 <div> 需要备份的文件名:<asp:TextBox ID="bfFile" runat="server" ...

  4. MySQL存储过程简介和引擎说明

  5. webpack前端构建工具学习总结(四)之自动化生成项目中的html页面

    接续上文:webpack前端构建工具学习总结(三)之webpack.config.js配置文件 插件的介绍文档:https://www.npmjs.com/package/html-webpack-p ...

  6. java httpclient 跳过证书验证

    import java.io.IOException;import java.net.InetAddress;import java.net.Socket;import java.net.Unknow ...

  7. 洛谷 P2617 Dynamic Ranking

    题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是多少(1≤k≤ ...

  8. Openjudge 2.5 6264:走出迷宫

    总时间限制:  1000ms 内存限制:  65536kB 描述 当你站在一个迷宫里的时候,往往会被错综复杂的道路弄得失去方向感,如果你能得到迷宫地图,事情就会变得非常简单. 假设你已经得到了一个n* ...

  9. PHP 头部utf-8

    只是自己用的一些存储,请各位看官大大勿怪. header("Content-Type: text/html;charset=utf-8"); 2019年04月10日

  10. shell脚本,文件里面的英文大小写替换方法。

    [root@localhost wyb]# cat daxiaoxie qweBNMacb eeeDFSmkl svdIOPtyu [root@localhost wyb]# cat daxiaoxi ...