哈希 poj 2002】的更多相关文章

n个点 求其中有几个正方形 n<1000 暴力4个点就不行了 大概2个点还可以 根基(x*x+y*y)%素数 hash 一下 告诉你2个点求 另外2个点 画个图推一下 重复要/2; #include<stdio.h> #include<algorithm> #include<vector> using namespace std; #define mod 10007 struct point { int x,y; }x[]; vector<point>…
经典好题. 题意是要我们找出所有的正方形.1000点,只有枚举咯. 如图,如果我们知道了正方形A,B的坐标,便可以推测出C,D两点的坐标.反之,遍历所有点作为A,B点,看C,D点是否存在.存在的话正方形数+1. 假设A点坐标为(x1,y1),B点坐标为(x2,y2),则根据三角形全等,易知 C点坐标:( x1+(y2-y1),y1-(x2-x1) ) D点坐标:( x2+(y2-y1),y2-(x2-x1) ) 当然,如果我们遍历任意两个点,一个正方形将会被计数四次(四条边).我们可以只判断斜率…
题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Hash_table { int x, y; struct Hash_table *next; }*Hash[prime]; void Hash_insert(int x, int y) { int key = (x + y) % prime; if(Hash[key] == NULL) { Hash[key] =…
Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 5749 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating abou…
题目链接:http://poj.org/problem?id=2002 题意:给定n个点,问有多少种方法可以组成正方形. 思路:我们可以根据两个点求出对应正方形[有2个一个在两点左边,一个在两点右边]另外两个点的左边.例如 已知:(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) 枚举两…
题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后,首先枚举p1,p2, 并判断p2是否在p1正下方或者左上角(因为每个正方形只有一条最右边或者是右下的边),按照下图计算p3,p4,判断p3,p4是否存在即可. 感想 排序时要注意和左上角这个信息相符,刚写完时用的是左下角,与升序排序不符合,会遗失部分正方形. 代码 #include <cstdio…
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33595   Accepted: 8811 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is…
http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那么,整个正方形就确定了,有两个方向. 因为, 设枚举的坐标为(x1, y1) & (x2, y2),所求的坐标是和x1,y1这个点相连,那么有方程如下. 1.垂直,向量积是0 2.边长相等,然后距离公式化简. 即可解出剩下的两个点. 然后要注意两个点要在正方形的同一侧,不然变了平行四边形了. 唤醒了…
Quicksum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16488   Accepted: 11453 Description A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will…
n个雪花 判断有没有相同的 正的和倒的相同都可以 哈希一下  比的少了就可以 #include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> using namespace std; #define MAXN 15010 #define mod 14997 int cnt[MAXN]; struct node { ]; }x[MAXN][]; bool jud(node a,…