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)的最大公约数. 证 ...
随机推荐
- DIV CSS 笔记
/*针对谷歌浏览器内核支持的CSS样式*/ <style type="text/css"> @media screen and (-webkit-min-device- ...
- 十五 Django框架,缓存
由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中,5 ...
- Java之泛型浅解
我觉得学习一个东西,首先得从概念上明白它大概是什么? “泛型”就是“参数化类型”,也就是是把类型当成了一种参数.之前我们看到得函数方法比如: public long add(int num1,int ...
- 多媒体的框架 - OpenCore框架概述
OpenCore是一个多媒体的框架,从宏观上来看,它主要包含了两大方面的内容:PVPlayer:提供媒体播放器的功能,完成各种音频 (Audio).视频(Video)流的回放(Playback)功能. ...
- FEC之我见四
接上文,来详细的说明一下FEC前向纠错的具体实现: FEC_matrix是一个比较常用的算法,Vandermonde,范德蒙矩阵是法国数学家范德蒙提出的一种各列为几何级数的矩阵. 范德蒙矩阵的定义: ...
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
- Mathf.Sin正弦
输入参数是弧度 Mathf.Sin public static float Sin(float f); Parameters Description Returns the sine of ang ...
- BZOJ3401:[USACO2009MAR]Look Up
浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...
- Poj 1887 Testing the CATCHER(LIS)
一.Description A military contractor for the Department of Defense has just completed a series of pre ...
- 类方法,实例方法,静态方法,@property的应用
class test(object): h = 'hello' w = 'world' def demo(self): print("demo") def test_class(s ...