POJ 1971-Parallelogram Counting,暴力1063ms!
刚学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!的更多相关文章
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- POJ 1971 Parallelogram Counting
题目链接: http://poj.org/problem?id=1971 题意: 二维空间给n个任意三点不共线的坐标,问这些点能够组成多少个不同的平行四边形. 题解: 使用的平行四边形的判断条件:对角 ...
- POJ 1791 Parallelogram Counting(求平行四边形数量)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- POJ 1971 统计平行四边形 HASH
题目链接:http://poj.org/problem?id=1971 题意:给定n个坐标.问有多少种方法可以组成平行四边形.题目保证不会有4个点共线的情况. 思路:可以发现平行四边形的一个特点,就是 ...
- poj 2021 Relative Relatives(暴力)
题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...
- poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】
题目: http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...
随机推荐
- GIMP 无法设置中文的问题解决
首先按照网上说的安装了language-pack-gnome-zh-hant 参考链接:http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?top ...
- ES-Mac OS环境搭建(1)
前言 由于elasticsearch依赖Java,所以先要配置上Java环境,并且Java JDK必须要求1.8以上,这里以安装Java 1.8为例.安装环境如下: elasticsearch6.5. ...
- HTTP 三次握手 建立连接 和 四次握手断开连接
三次握手建立连接 第一次握手:主机A发送位码为syn=1,随机产生seq number=1234567的数据包到服务器,主机B由SYN=1知道,A要求建立联机: 第二次握手:主机B收到请求后要确 ...
- mysql> set sql_mode='no_auto_value_on_zero';
mysql> set sql_mode='no_auto_value_on_zero';
- (五)maven之外置maven
eclipse外置maven eclipse内置的maven插件是固定版本,如果要用其他版本的maven,可以使用外置maven. ① 在菜单栏上点击“Windows”à“Preferences ...
- nginx 编译某个模板的问题./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library stati
root@hett-PowerEdge-T30:/usr/local/src/nginx-1.9.8# ./configure --prefix=/usr/local/nginx --add-mod ...
- 获取CPU相关信息
实现效果: 知识运用: WMI管理类中的ManagementObjectCollection类 ManagementObjectSearcher类的Get方法 和ManagementObje ...
- VC-基础:MFC单文档程序架构解析
MFC单文档程序架构解析 这里我以科院杨老师的单文档程序来分析一下MFC单文档的程序架构,纯属个人见解,不当之处烦请指教! 首先我们了解到的是 图(一) theApp 是唯一一个在程序形成的时候就存在 ...
- 修改linux的时区问题
修改linux的时区问题 配置服务器节点上的时区的步骤: 1.先生成时区配置文件Asia/Shanghai,用交互式命令 tzselect 即可: 2.拷贝该时区文件,覆盖系统本地时区配置: cp / ...
- 实现类似AOP的封装和配置
这是张孝祥老师Java进阶讲解中最后一个视频,就是实现类似spring中的AOP的封装和配置,特别特别小型的一个框架雏形,但是spring中的核心思想还是体现出来了,真的厉害,张老师!!! 一.重点知 ...