题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055

题意: 给出 n 组坐标 x, y, 输出其中的正多边形个数 . 其中 x, y 均为整数.

思路: x, y 为整数, 所以只存在正方形, 不会有其他正多边形 . 那么只需要枚举正方形的对角线即可 .

代码:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std; const int MAXN = 1e3 + ;
const int H = 1e4 + ; struct node{
int x, y, next;
}gel[MAXN]; ll ans;
int head[H];
int indx, n;
int ptx[MAXN], pty[MAXN]; void init(void){
memset(head, -, sizeof(head));
indx = ;
ans = ;
} void add(int x, int y){
int h = (x * x + y * y) % H;
gel[indx].x = x;
gel[indx].y = y;
gel[indx].next = head[h];
head[h] = indx++;
} bool find(int x, int y){
int h = (x * x + y * y) % H;
for(int i = head[h]; i != -; i = gel[i].next){
if(x == gel[i].x && y == gel[i].y) return true;
}
return false;
} int main(void){
while(~scanf("%d", &n)){
init();
for(int i = ; i < n ; i++){
scanf("%d%d", &ptx[i], &pty[i]);
add(ptx[i], pty[i]);
}
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
if(i == j) continue;
int x1 = ptx[i] - (pty[i] - pty[j]);
int y1 = pty[i] + (ptx[i] - ptx[j]);
int x2 = ptx[j] - (pty[i] - pty[j]);
int y2 = pty[j] + (ptx[i] - ptx[j]);
if(find(x1, y1) && find(x2, y2)) ans++;
}
}
printf("%lld\n", ans >> );
}
return ;
}

hdu6055(求正方形个数)的更多相关文章

  1. m*n 矩阵中求正方形个数

    <?php /** * Notes: * User: liubing17 * DateTime: 2019-10-17 17:10 */ function get($m, $n){ /* * 获 ...

  2. HDU 4739 求正方形个数

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...

  3. C语言辗转相除法求2个数的最小公约数

    辗转相除法最大的用途就是用来求两个数的最大公约数. 用(a,b)来表示a和b的最大公约数. 有定理: 已知a,b,c为正整数,若a除以b余c,则(a,b)=(b,c). (证明过程请参考其它资料) 例 ...

  4. 求N个数的最大公约数和最小公倍数(转)

    除了分解质因数,还有另一种适用于求几个较小数的最大公约数.最小公倍数的方法 下面是数学证明及算法实现 令[a1,a2,..,an] 表示a1,a2,..,an的最小公倍数,(a1,a2,..,an)表 ...

  5. 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]

    [本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...

  6. LightOj 1024 - Eid (求n个数的最小公约数+高精度)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1024 题意:给你n(2<=n<=1000)个数, 然后求n个数的最小公倍数 ...

  7. wikioi 1202 求和(求n个数的和)

    /*============================================================= 1202 求和 题目描述 Description 求n个数的和 输入描述 ...

  8. 求n个数中的最大或最小k个数

    //求n个数中的最小k个数        public static void TestMin(int k, int n)        {            Random rd = new Ra ...

  9. 求两个数的最大公约数(Euclid算法)

    求两个数 p 和 q 的最大公约数(greatest common divisor,gcd),利用性质 如果 p > q, p 和 q 的最大公约数 = q 和 (p % q)的最大公约数. 证 ...

随机推荐

  1. 目标检测 — Inception-ResNet-v2

    这篇文章介绍的网络有Inception V1.Inception V2.Inception V3.Inception V4与Inception-ResNet-V2. 1.Inception V1 主要 ...

  2. Selenium-几种等待方式

    强制等待 一直使用的time.sleep(5),可以放在任意地方,不好的地方,不太准确确定时间 隐形等待 driver.implicitly_wait(5) 设置了一个最长等待时间,如果在规定时间内网 ...

  3. Tomcat_总结_02_单机多实例

    一.tomcat下载及环境变量配置 1.tomcat下载 下载地址:tomcat官网 2.环境变量配置 只用配置一个CATALINA_HOME就可以了 二.CATALINA_HOME 与 CATALI ...

  4. stl_multimap.h

    stl_multimap.h // Filename: stl_multimap.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...

  5. Redo Log File(inactive、active)损坏,处理恢复对策

    redolog的生命周期中共有四种状态:current -> 正在使用的active -> 非正在使用的,对应的Dirty Block还没有完全写入到数据文件中inactive -> ...

  6. 洛谷【P1236】算24点

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  7. Poj 2503 Babelfish(Map操作)

    一.Description You have just moved from Waterloo to a big city. The people here speak an incomprehens ...

  8. 第二课 go语言的结构

    1 go 语言结构 package main import "fmt" func main() { /* 这是我的第一个简单的程序 */ fmt.Println("Hel ...

  9. HttpApplication 对象的创建过程及HttpModule过滤器的内部实现过程

    最近通过Reflector学习了一下asp.net内部的原理,做做笔记,方便以后查阅. 先看下HttpApplication 对象的创建过程 从IHttpHandler applicationInst ...

  10. linux命令-任务计划-cron

    任务计划,有时间规律的执行某些事情. 查看任务计划:crontab -l 指定用户:crontab -l  -u 用户名 该用户没有任务计划. 自定义任务计划 进入一个操作和vim类似的界面 用空格分 ...