Description

On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
 

Input

The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
 

Output

For each case, output a number means how many different regular polygon these points can make.
 
Sample

Sample Input

Sample Output

题意:

  给定n个整数点,问能组成多少正n边形。

思路:

  因为给出的是整数点,所以只可能是正方形

  可以枚举正方形的对角线,因为有两条对角线,最后答案要/2

  也可以枚举正方形的边,因为有四条边,答案要/4

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> #define MAX 2000 using namespace std; struct node
{
int x,y;
} p[MAX]; int vis[MAX][MAX]; int solve(int node1,int node2)
{
int x = p[node1].x - p[node2].x;
int y = p[node1].y - p[node2].y;
int ans=;
if(p[node1].x-y>= && p[node1].y+x>= && p[node2].x-y>= && p[node2].y+x>= )//判断成正方形的条件
if(vis[p[node1].x-y][p[node1].y+x] && vis[p[node2].x-y][p[node2].y+x])//判断两个点是否存在
ans++;
if(p[node1].x+y>= && p[node1].y-x>= && p[node2].x+y>= && p[node2].y-x>= )
if( vis[p[node1].x+y][p[node1].y-x] && vis[p[node2].x+y][p[node2].y-x])
ans++;
return ans;
} int main()
{
int n,x,y;
while(scanf("%d",&n)!=EOF)
{
int ans = ;
memset(vis,,sizeof(vis));
//vis数组用来查看是否存在,结构体p用来存所有的点
for(int i=; i<n; i++)
{
scanf("%d%d",&x,&y);
vis[x+][y+] = ;//注意+200是为了将负数化为正数
p[i].x = x+;
p[i].y = y+;
}
//枚举所有的点
for(int i=; i<n; i++)
{
for(int j=i+; j<n; j++)
{
ans += solve(i,j);
}
} ans /= ;//因为枚举的是边长,所以最后除以4 printf("%d\n",ans);
}
return ;
}

HDU6055 Regular polygon(计算几何)的更多相关文章

  1. hdu6055 Regular polygon 脑洞几何 给定n个坐标(x,y)。x,y都是整数,求有多少个正多边形。因为点都是整数点,所以只可能是正四边形。

    /** 题目:hdu6055 Regular polygon 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意:给定n个坐标(x,y).x,y都 ...

  2. hdu 4033 Regular Polygon 计算几何 二分+余弦定理

    题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. # ...

  3. HDU 6055 17多校 Regular polygon(计算几何)

    Problem Description On a two-dimensional plane, give you n integer points. Your task is to figure ou ...

  4. HDU 6055 Regular polygon

    Regular polygon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)

    题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...

  6. 2017 Multi-University Training Contest - Team 2 &hdu 6055 Regular polygon

    Regular polygon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. HDU 6055 - Regular polygon | 2017 Multi-University Training Contest 2

    /* HDU 6055 - Regular polygon [ 分析,枚举 ] 题意: 给出 x,y 都在 [-100, +100] 范围内的 N 个整点,问组成的正多边形的数目是多少 N <= ...

  8. HDU 6055 Regular polygon —— 2017 Multi-University Training 2

    Regular polygon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. 【2017多校训练2+计算几何+板】HDU 6055 Regular polygon

    http://acm.hdu.edu.cn/showproblem.php?pid=6055 [题意] 给定n个格点,问有多少个正多边形 [思路] 因为是格点,只可能是正方形 枚举正方形的对角线,因为 ...

随机推荐

  1. indexOf和lastIndexOf的使用

    indexOf()和 lastIndexOf()是返回位置index的两个方法:都是接收两个参数,其中,indexOf()方法从数组的开头(位 置 0)开始向后查找:lastIndexOf()方法则从 ...

  2. eclipse中Build Path 导入的包和复制到 lib 包的区别

    Java Build Path是我们编译需要的包,在比如在import ***.***.***时如果没用Java Build Path导入包的话类里面就有红叉,说不识别这个类,build path只是 ...

  3. Example007关闭窗口时关闭父窗口

    <!--实例007关闭窗口时刷新父窗口--> <!DOCTYPE html> <html lang="en"> <head> < ...

  4. Java程序设计---io流读取文件内容并将其逆值输出到控制台

    import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileR ...

  5. python实现折半查找算法&&归并排序算法

    今天依旧是学算法,前几天在搞bbs项目,界面也很丑,评论功能好像也有BUG.现在不搞了,得学下算法和数据结构,笔试过不了,连面试的机会都没有…… 今天学了折半查找算法,折半查找是蛮简单的,但是归并排序 ...

  6. PowerShell使用-debug定位问题

    PowerShell就像它的名字一样,很强大,用起来很方便,所以微软基本上所有的主流企业级产品都支持PowerShell,Azure也不例外.通过Azure门户网站固然是简单直观,但对于很多IT管理员 ...

  7. Unity 游戏框架搭建 (六) 关于框架的一些好文和一些思考

      在进行项目架构阶段,游戏框架可以解决一部分问题.剩下的架构问题还需要根据不同的项目解决.总之游戏框架是游戏架构的一部分. 关于锤子和钉子:   最近又拿起了<代码大全>和<暗时间 ...

  8. NEWS-包名-baseTest-类名-baeseDao

    package baseTest; import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedS ...

  9. int-整数+bool-布尔功能介绍

    int #创建和转换 #a = 123#a = int(123)#转换 #Age = "22"#Age = int(22)#1.当前整数用二进制表示的最小位数 # age = 50 ...

  10. Redis Pipeline原理分析

    转载请注明出处:http://www.cnblogs.com/jabnih/ 1. 基本原理 1.1 为什么会出现Pipeline Redis本身是基于Request/Response协议的,正常情况 ...