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. 如何在前端模版引擎开发中避免使用eval函数

    前段时间,想着自己写一个简单的模版引擎,便于自己平时开发demo时使用.于是根据自己对模版引擎的理解,定义自己的模版格式,然后,根据自己定义的格式,编写处理函数,将模版标签中的字符串,解析成可执行的字 ...

  2. ICG_System之全自动代码生成器V2.0版本

    大家好! 早在2014年本人就已经利用业余时间开发自己的ICG之代码生成器系统.依靠bootstrap的崛起本人也在不断完善此应用.目的是为了减少开发人员的工作量. 减少不必要的复制粘贴操作,该系统已 ...

  3. gdb常用命令及使用gdb调试多进程多线程程序

    一.常用普通调试命令 1.简单介绍GDB 介绍: gdb是Linux环境下的代码调试⼯具.使⽤:需要在源代码⽣成的时候加上 -g 选项.开始使⽤: gdb binFile退出: ctrl + d 或 ...

  4. linux使用crontab实现PHP执行定时任务

    首先说说cron,它是一个linux下的定时执行工具.根用户以外的用户可以使用 crontab 工具来配置 cron 任务. 所有用户定义的 crontab 都被保存在/var/spool/cron ...

  5. MySQL各模块工作配合

    MySQL各模块工作配合 在了解了 MySQL 的各个模块之后,我们再看看 MySQL 各个模块间是如何相互协同工作的 .接下来,我们通过启动 MySQL,客户端连接,请求 query,得到返回结果, ...

  6. Linux下配置tomcat+apr+native应对高并发

    摘要:在慢速网络上Tomcat线程数开到300以上的水平,不配APR,基本上300个线程狠快就会用满,以后的请求就只好等待.但是配上APR之后,Tomcat将以JNI的形式调用Apache HTTP服 ...

  7. 遇到looper之类关于消息循环的

    原因大概是因为无法创建消息循环,这时候要考虑函数是否要在主线程或者不在主线程中进行,改一下即可

  8. 规定CSS的属性仅在IE下生效 在非IE浏览器下不生效

    css中判断IE版本的语句<!--[if gte IE 6]> Only IE 6/+ <![endif]-->: 1. <!--[if !IE]> 除IE外都可识 ...

  9. Spring (3.2.4) 常用jar 包解析

    Spring (3.2.4) 常用jar 包解析 基本jar包 spring-aop-3.2.4.RELEASE.jar spring-aspects-3.2.4.RELEASE.jar spring ...

  10. Python3 面向对象程序设计(类)

    一.自定义类 1.属性与方法 格式: class classname: def __init__(self,a,b): self.a=a   self.b=b def ... >一般都有一个__ ...