POJ2002 Squares(枚举)】的更多相关文章

题目链接. 分析: 普遍的做法是:先枚举两个点,通过数学公式得到另外2个点,使得这四个点能够成正方形.然后检查散点集中是否存在计算出来的那两个点,若存在,说明有一个正方形. 但这种做法会使同一个正方形按照不同的顺序被枚举了四次,因此最后的结果要除以4. 已知: (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…
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 about its centre by 90 degrees gives the same polygon. It is not the only polygon with the latte…
                                                       Squares 题意:二维坐标轴给出n个点求有多少个正方形. 要是平时做比赛的话毫无疑问会想到用二分去写这道题,但毕竟出现在hash专题里,所以自然用hash去攻克,但是完全没有思路,于是,,网上找了题解,让我感叹的是我们做hash的题怎么知道用哪种hash函数呢..这道题以坐标平方和再对hash数组大小取余,这样离散化感觉有点钻数据空子,但hash是有处理冲突的能力的,存在冲突怎么办呢…
题目链接:http://poj.org/problem?id=2002 给定一堆点,求这些点里哪些点可以构成正方形,题目给定n<=1000,直接枚举四个点是肯定会超时的,因此要做一些优化. 有公式,已知两个点在正方形对角,分别是(x1,y1)和(x2,y2),那么围成正方形后另外两个点(x3,y3)和(x4,y4)分别为: x3 = x2 - (x2 - y1) y3 = x2 + (x2 - x1) x4 = x1 - (x2 - y1) y4 = y1 + (x2 - x1) 那么我们需要枚…
题意描述:有一堆平面散点集,任取四个点,求能组成正方形的不同组合方式有多少.相同的四个点,不同顺序构成的正方形视为同一正方形. 思路变迁: 1.最简单的方法,直接暴力搜索,即依次取四个顶点,根据其坐标判断是否能组成正方形.组成正方形的条件是四个顶点可组成的六条边里面,有四条相等,剩下两条相等.当然由于其时间复杂度为O(n^4),所以提交结果为TLE 2.考虑降低时间复杂度.如任取三个顶点,根据组成正方形的条件计算得到第四个顶点,判断其是否在点的集合内,其复杂度为O(n^3).或者任取两个顶点,根…
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/problem/D Description Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of…
Problem UVA12113-Overlapping Squares Accept:116  Submit:596 Time Limit: 3000 mSec  Problem Description  Input The input consists of several test cases. Each test case is contained in five lines and each line contains nine characters. If the horizontal…
Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 17487   Accepted: 6643 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://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. #include<iostream> #i…
http://poj.org/problem?id=2002 题意:给出n组坐标,判断这些坐标能组成的正方形的个数. 思路:参考某大神的想法,先枚举两个点,然后利用公式表示出另外两个点,判断这两个点是否在这n组坐标中,其中查找另两个坐标用的set容器. 已知 (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-x…