hdu6055(求正方形个数)
题目链接: 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(求正方形个数)的更多相关文章
- m*n 矩阵中求正方形个数
<?php /** * Notes: * User: liubing17 * DateTime: 2019-10-17 17:10 */ function get($m, $n){ /* * 获 ...
- HDU 4739 求正方形个数
九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...
- C语言辗转相除法求2个数的最小公约数
辗转相除法最大的用途就是用来求两个数的最大公约数. 用(a,b)来表示a和b的最大公约数. 有定理: 已知a,b,c为正整数,若a除以b余c,则(a,b)=(b,c). (证明过程请参考其它资料) 例 ...
- 求N个数的最大公约数和最小公倍数(转)
除了分解质因数,还有另一种适用于求几个较小数的最大公约数.最小公倍数的方法 下面是数学证明及算法实现 令[a1,a2,..,an] 表示a1,a2,..,an的最小公倍数,(a1,a2,..,an)表 ...
- 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]
[本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...
- LightOj 1024 - Eid (求n个数的最小公约数+高精度)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1024 题意:给你n(2<=n<=1000)个数, 然后求n个数的最小公倍数 ...
- wikioi 1202 求和(求n个数的和)
/*============================================================= 1202 求和 题目描述 Description 求n个数的和 输入描述 ...
- 求n个数中的最大或最小k个数
//求n个数中的最小k个数 public static void TestMin(int k, int n) { Random rd = new Ra ...
- 求两个数的最大公约数(Euclid算法)
求两个数 p 和 q 的最大公约数(greatest common divisor,gcd),利用性质 如果 p > q, p 和 q 的最大公约数 = q 和 (p % q)的最大公约数. 证 ...
随机推荐
- java:解决eclipse配置Tomcat时找不到server选项
http://blog.csdn.net/wugangsunny/article/details/25246565 集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在 ...
- 代码题(2)— 统计所有小于非负整数 n 的质数的数量
质数也叫素数,只能被1和它本身整除的. 利用筛选法. class Solution { public: int countPrimes(int n) { ) ; ; vector<); ;i&l ...
- codeforces 707B B. Bakery(水题)
题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include ...
- poj-2478 Farey Sequence(dp,欧拉函数)
题目链接: Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14230 Accepted: ...
- SQL关联查询中on与where
微信公众号:刺刺刺猬的优雅 前段时间,做一个查询,打算用left join查询存在于A表但不存在于B表记录,但怎么查都不对,原因是把所有filter全部放在了where语句中,因此回头看了资料,记录一 ...
- bzoj 1941 Hide and Seek —— K-D树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1941 曼哈顿最小距离估价:max( 0, t[x].mn[i] - v.p[i] ) + m ...
- 如何避免这个delete from tb_name不带条件的操作
那么,我们如何避免这个delete from tb_name不带条件的呢?其实是有办法的,但这只针对运维DBA或者DBA在操作时候有用,但对于PHP和JAVA程序,它的连接操作方式,就没办法避免了 s ...
- NB-IoT知识
通常,我们把物联网设备分为三类: ①无需移动性,大数据量(上行),需较宽频段,比如城市监控摄像头. ②移动性强,需执行频繁切换,小数据量,比如车队追踪管理. ③无需移动性,小数据量,对时延不敏感,比如 ...
- 【转】Jquery折叠效果
转自:http://www.cnblogs.com/clc2008/archive/2011/10/25/2223254.html <!DOCTYPE html PUBLIC "-// ...
- VisualGDB系列1:VisualGDB总体概述
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文总体介绍VisualGDB能给你带来 ...