POJ -- 2002
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#define MAXN 1111
using namespace std;
class Point{
public:
int x,y;
bool operator < (const Point &p) const{
if(x == p.x) return y < p.y;
return x < p.x;
}
bool operator == (const Point &p) const{
return x == p.x && y == p.y;
}
};
Point P[MAXN];
bool Binary_Search(const Point target,int len){
int l = ,r = len,mid;
while(l <= r){
mid = (l+r) >> ;
if(target == P[mid]) return true;
else if(target < P[mid]) r = mid-;
else l = mid+;
}
return false;
}
int main(){
int n,ans;
freopen("in.c","r",stdin);
while(~scanf("%d",&n) && n){
for(int i = ;i < n;i ++) scanf("%d%d",&P[i].x,&P[i].y);
sort(P,P+n);
ans = ;
for(int i = ;i < n;i ++){
for(int j = i+;j < n;j ++){
Point tmp1,tmp2;
tmp1.x = P[i].x+P[i].y-P[j].y,tmp1.y = P[i].y-P[i].x+P[j].x;
tmp2.x = P[j].x+P[i].y-P[j].y,tmp2.y = P[j].y-P[i].x+P[j].x;
if(Binary_Search(tmp1,n) && Binary_Search(tmp2,n)) ans++;
}
}
printf("%d\n",ans >> );
}
return ;
}
POJ -- 2002的更多相关文章
- POJ 2002 统计正方形 HASH
题目链接:http://poj.org/problem?id=2002 题意:给定n个点,问有多少种方法可以组成正方形. 思路:我们可以根据两个点求出对应正方形[有2个一个在两点左边,一个在两点右边] ...
- POJ 2002 Squares 哈希
题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Has ...
- POJ 2002 Squares 几何, 水题 难度: 0
题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后 ...
- POJ 2002 Squares 数学 + 必须hash
http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那 ...
- POJ 2002 Squares 解题报告(哈希 开放寻址 & 链式)
经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方 ...
- POJ 2002 Squares【值得摸索的一道二分+点旋转】
id=2002">Squares 很好的一道二分,事实上本来我是没有思路的,看了基神的题解之后才似乎明确了点. 题意:给出最多有1000个点,问这些点能够组成多少个正方形 分析:先想想 ...
- 哈希 poj 2002
n个点 求其中有几个正方形 n<1000 暴力4个点就不行了 大概2个点还可以 根基(x*x+y*y)%素数 hash 一下 告诉你2个点求 另外2个点 画个图推一下 重复要/2; #inclu ...
- POJ 2002 Squares
二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...
- Ultra-QuickSort (poj 2002)
Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...
随机推荐
- IAP (In-App Purchase)中文文档
内容转自:http://yarin.blog.51cto.com/1130898/549141 一.In App Purchase概览 Store Kit代表App和App Store之间进行通信.程 ...
- UVA 1401 Remember the Word(用Trie加速动态规划)
Remember the Word Neal is very curious about combinatorial problems, and now here comes a problem ab ...
- UVA 11464 Even Parity(部分枚举 递推)
Even Parity We have a grid of size N x N. Each cell of the grid initially contains a zero(0) or a on ...
- Flash Professional CS6 安装zxp插件
说明 头两天因工作原因需要使用DragonBones,他的工作方式是的Flash Professional CS5.5以上的环境. DragonBones提供的是一个文件名为:xzp的文件,在Wind ...
- Java进程CPU使用率高排查
Java进程CPU使用率高排查 生产java应用,CPU使用率一直很高,经常达到100%,通过以下步骤完美解决,分享一下.1.jps 获取Java进程的PID.2.jstack pid >> ...
- jQuery学习 day01
最近受某大牛指点(我不会说他姓范),了解了一下jQuery,据说很牛X,就了解了一下,第一天,分享给大家一些心得吧. 1.首先就是导入jQuery文件了,这里我是去jQuery官网下载的.(大家可以去 ...
- Cocos2d-x课程大纲/学习路线
Cocos2d-x课程大纲/学习路线 这是什么? 这个一个Cocos2d-x技术路线的课程大纲/学习大纲. 你能用它做什么? 如果你是找工作的人, 利用本大纲, 你可以学习Cocos2d-x, 做一个 ...
- php设计模式:工厂模式
php设计模式:工厂模式 意图: 定义一个用于创建对象的接口,让子类决定实例化哪一个类. 工厂模式实现: 工厂模式中任何创建对象的工厂类都要实现这个接口,实现接口的方法体中都要实现接口中的方法,它声明 ...
- osg学习笔记2, 命令行参数解析器ArgumentParser
ArgumentParser主要负责命令行参数的读取 #include <osgDB/ReadFile> #include <osgViewer/Viewer> int mai ...
- SQL Express几个版本的区别
对于这三个文件:SQLEXPR32_x86_CHS.exe.SQLEXPR_x86_CHS.exe. SQLEXPR_x64_CHS.exe,大家一看就知道是sqlserver的express版本,但 ...