Squares<哈希>
Description
So we all know what a square looks like, but can we find all possible squares that can be formed from a set of stars in a night sky? To make the problem easier, we will assume that the night sky is a 2-dimensional plane, and each star is specified by its x and y coordinates.
Input
Output
Sample Input
4
1 0
0 1
1 1
0 0
9
0 0
1 0
2 0
0 2
1 2
2 2
0 1
1 1
2 1
4
-2 5
3 7
0 0
5 2
0
Sample Output
1
6
1 就是看看给出的点能组成几个正方形;
不要四个四个的组合,想也会超时,任意两个组合,然后计算出另外两个点;
再去查询是否存在;结果要除以4的;
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool x[][];//我才不告诉你其实数据是-2000--2000
int si[],sj[];
int f(int a,int b)
{
if(x[a+][b+])
return ;
return ;
}
int main()
{
int a,b,i,j,n,sum;
int x1,y1,x2,y2,x3,y3,x4,y4;
while(scanf("%d",&n)&&n)
{
sum=;
memset(x,,sizeof(x));
for(i=; i<n; i++)
{
scanf("%d %d",&a,&b);
si[i]=a;
sj[i]=b;
x[a+][b+]=;
}
for(i=; i<n; i++)
{
x1=si[i];
y1=sj[i];
for(j=; j<i; j++)
{
x2=si[j];
y2=sj[j];
x3=x1+(y1-y2);//计算剩下两个点
y3= y1-(x1-x2);
x4=x2+(y1-y2);
y4= y2-(x1-x2);
if(f(x3,y3)&&f(x4,y4))
sum++;
x3=x1-(y1-y2);
y3= y1+(x1-x2);
x4=x2-(y1-y2);
y4= y2+(x1-x2);
if(f(x3,y3)&&f(x4,y4))
sum++;
}
}
printf("%d\n",sum/);//记得除以4
}
return ;
}
Squares<哈希>的更多相关文章
- Squares(哈希)
Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14328 Accepted: 5393 Description A sq ...
- POJ-2002 Squares,哈希模板+数学公式!
Squares 题意:二维坐标轴给出n个点求有多少个正方形. 要是平时做比赛的话毫无疑问会 ...
- POJ 2002 Squares 哈希
题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Has ...
- poj 2002 Squares 几何二分 || 哈希
Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 15137 Accepted: 5749 Descript ...
- URAL - 1486 Equal Squares 二维哈希+二分
During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...
- 【URAL 1486】Equal Squares(二维哈希+二分)
Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...
- POJ 2002 Squares 解题报告(哈希 开放寻址 & 链式)
经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方 ...
- PKU 2002 Squares(二维点哈希+平方求余法+链地址法)
题目大意:原题链接 给定平面上的N个点,求出这些点一共可以构成多少个正方形. 解题思路: 若正方形为ABCD,A坐标为(x1, y1),B坐标为(x2, y2),则很容易可以推出C和D的坐标.对于特定 ...
- poj Squares n个点,共能组成多少个正方形 二分 + 哈希
题目链接:http://poj.org/problem?id=2002 测试数据: 41 00 11 10 090 01 02 00 21 22 20 11 12 14-2 53 70 05 20 有 ...
随机推荐
- MFC——error LNK2005: "protected: static struct AFX_MSGMAP
好久没弄VC程序了,今天弄了下,还会用公司给的窗口重绘作为基类来实现,竟然报了这个错误. 找了一下是这里: 有个窗口重绘类是基类: class CBaseDlg : public CDialog 新建 ...
- The Boost C++ Libraries
" ...one of the most highly regarded and expertly designed C++ library projects in the world.&q ...
- spring mvc DispatcherServlet详解之四---视图渲染过程
整个spring mvc的架构如下图所示: 现在来讲解DispatcherServletDispatcherServlet的最后一步:视图渲染.视图渲染的过程是在获取到ModelAndView后的过程 ...
- Optimized Pagination using MySQL---reference
Dealing with large data sets makes it necessary to pick out only the newest or the hottest elements ...
- 使用 Xcode 和 Android Studio 管理 iOS 和 Android 项目版本
在移动应用开发和运营的过程中,版本管理是一个老生常谈的基础问题,一些版本的基本概念也常常会困扰我们的研发和运营人员.同时,手动管理软件版本,也常常会因为不小心导致后续的发布和更新问题. 这里,我准备了 ...
- CentOS使用sendmail发送邮件
1.安装sendmail yum -y install sendmail 2.启动sendmail服务 service sendmail start 3.将发件内容写入mail.txt mail -s ...
- 关于黑名单IP的设置
最近在做一个项目的时候,需要做一个自动的黑名单设置,也就是将一天内重复出错的超过一定次数的手机号,和IP给加入黑名单里面,下次请求的时候先判断是否在黑名单里. 这个是获取IP地址的方法 private ...
- win7 下配置 java 环境变量
首先,你应该已经安装了 java 的 JDK 了,笔者安装的是:jdk-7u7-windows-x64 接下来主要讲怎么配置 java 的环境变量,也是为了以后哪天自己忘记了做个备份 1.进入“计算机 ...
- memcached并发处理
memcached(十八)并发原语CAS与GETS操作 Memcached 并发控制 CAS 协议 memcache控制高并发问题 使用memcached进行并发控制 memcached的最佳实践方案
- 查看sql语句执行时间/测试sql语句性能
写程序的人,往往需要分析所写的SQL语句是否已经优化过了,服务器的响应时间有多快,这个时候就需要用到SQL的STATISTICS状态值来查看了. 通过设置STATISTICS我们可以查看执行SQL时的 ...