poj2002Squares(点集组成正方形数)
可以枚举两个点,因为是正方形两外两点可以由已知求出,据说可以根据三角形全等求出下列式子,数学渣不会证。。。
已知: (x1,y1) (x2,y2)
则: x3=x1+(y1-y2) y3= y1-(x1-x2)
x4=x2+(y1-y2) y4= y2-(x1-x2)
或
x3=x1-(y1-y2) y3= y1+(x1-x2)
x4=x2-(y1-y2) y4= y2+(x1-x2)
然后就可以hash或者二分做了,这里只用hash做的
应该算是简单的hash解决冲突的应用,放一个邻接表里。
两点需正反枚举两次,才能保证两种位置的正方形都被枚举到。
最后的结果需要除4,因为重复枚举了。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define mod 99991
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
int x,y;
point(int x=,int y=):x(x),y(y){}
}p[N],o[N];
int next[N],head[mod],t;
void insert(int i)
{
int key = (p[i].x*p[i].x+p[i].y*p[i].y)%mod;
next[t] = head[key];
o[t].x = p[i].x;
o[t].y = p[i].y;
head[key] = t++;
}
int find(point a)
{
int key = (a.x*a.x+a.y*a.y)%mod;
int i;
for(i = head[key] ; i!= - ; i = next[i])
{
if(o[i].x==a.x&&o[i].y == a.y) return ;
}
return ;
}
bool cmp(point a,point b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
int n,i,j;
while(scanf("%d",&n)&&n)
{
memset(head,-,sizeof(head));
t = ;
for(i = ; i <= n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
insert(i);
}
//sort(p+1,p+n+1,cmp);
int ans = ;
for(i = ; i <= n ;i++)
for(j = ; j <= n; j++)
{
if(i==j) continue;
point p1,p2;
p1.x = p[i].x+(p[i].y-p[j].y);
p1.y = p[i].y-(p[i].x-p[j].x);
p2.x = p[j].x+(p[i].y-p[j].y);
p2.y = p[j].y-(p[i].x-p[j].x);
if(!find(p1)) continue;
if(!find(p2)) continue;
ans++;
}
printf("%d\n",ans/);
}
return ;
poj2002Squares(点集组成正方形数)的更多相关文章
- [Bnuz OJ]1176 小秋与正方形
传送门 问题描述 某天,acm的小秋拿到了一张很大很大的纸.他现在打算把它撕成正方 形.但是他没有任何工具,没有尺子,所以他尝试一种有趣的方法切分矩形.假设这是一个a*b的矩形(a>b),那么小 ...
- 洛谷 P5206 - [WC2019]数树(集合反演+NTT)
洛谷题面传送门 神仙多项式+组合数学题,不过还是被我自己想出来了( 首先对于两棵树 \(E_1,E_2\) 而言,为它们填上 \(1\sim y\) 使其合法的方案数显然是 \(y\) 的 \(E_1 ...
- tc 146 2 RectangularGrid(数学推导)
SRM 146 2 500RectangularGrid Problem Statement Given the width and height of a rectangular grid, ret ...
- zjoi2016 day1【bzoj4455】【bzoj4456】
首先做了T2的旅行者,看到bz上面过的人数比较多.. 考试的时候完全没有想太多.一闪而过了分块思想,然后就没有然后了.. 大视野上面有题解,竟然是一个初中生写的..? 正解其实是“分治”,每次选择中轴 ...
- Codeforces Round #141 (Div. 2)
A. Is your horseshoe on the other hoof? 模拟题意. B. Two Tables 暴力枚举\(x,y\). C. Fractal Detector 显然,判断图形 ...
- POJ 2002 Squares 解题报告(哈希 开放寻址 & 链式)
经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方 ...
- 数学(容斥计数):LNOI 2016 方
Description 上帝说,不要圆,要方,于是便有了这道题.由于我们应该方,而且最好能够尽量方,所以上帝派我们来找正方形 上帝把我们派到了一个有N行M列的方格图上,图上一共有(N+1)×(M+1) ...
- The square chest
The square chest Sophia pressed the button in front of her, slamming her fist against it. The door r ...
- Tyvj P1813 [JSOI2008]海战训练
P1813 [JSOI2008]海战训练 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 为了准备高层峰会,元首命令武装部队必须处于高度戒备.警察将监视每一条 ...
随机推荐
- Unix/Linux编程实践教程(一:进程、管道)
execvp在程序中启动新程序: 用fork创建新进程: forkdemo2代码: 测试fork的时候参考<Linux权威指南>阅读笔记(3) 使用了patch: [root@local ...
- Spring+Quartz实现定时执行任务的配置
1.要想使用Quartz 必须要引入相关的包:以下是我在项目中gradle中的配置: compile 'org.quartz-scheduler:quartz:2.1.1' 2.Scheduler的配 ...
- Moo University - Financial Aid
Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...
- oracle驱动地址
D:\app\LHComputer\product\12.1.0\dbhome_1\ODP.NET\bin\2.x
- CurrentHashMap的实现原理
转载:http://wiki.jikexueyuan.com/project/java-collection/concurrenthashmap.html 概述 我们在之前的博文中了解到关于 Hash ...
- touch 命令
gcc 或 mmm等命令进行编译时,判断文件是否改变是根据文件的修改日期做判断的,但有些情况改变文件后,可能时间没有很快更新,导致编译不到,那么用 touch ./* 把对应目录下文件时间更新一下再编 ...
- C#和SQl 注入字符串的攻击 和 防止注入字符转的攻击
--SQl中 --建立ren的数据库,插入一条信息 create database ren go use ren go create table xinxi ( code ) primary key, ...
- Android权限安全(1)自定义,检查,使用权限
1.自定义权限: <!-- 定义自定义权限 --> <permission android:name="com.example.f6k5i8.checkpermission ...
- H5网站借鉴
http://www.rdinfo.com.cn/index.shtml http://www.winployee.com/ http://www.lkkdesign.com/ http://www. ...
- MSM8974 fastboot烧写软件
fastboot烧写是在aboot阶段做的,所以空板没有完整烧写aboot及其boot sequence前的image是没法使用fastboot的.在手机开机状态下,执行: adb re ...