Problem 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 Input
4
0 0
0 1
1 0
1 1
6
0 0
0 1
1 0
1 1
2 0
2 1
 
Sample Output
1
2
 
题意:给出n个坐标点(皆在格点上),求问这些点可以构成几个正多边形?
题解:
1.所有点皆在格点上只有一个情况,那便是正四边形
 2.任意枚举两个点,求出另两个点的坐标,来观察是否在给出的点中,若皆存在,cnt++。
求另两个坐标的方法:设已知两个点为a,b(a.x<b.x),另两个点为c,d,设c是直接与b相连的,d是直接与a相连的
如图方法可以求出c-b,d-a的x,y变化分别为 disx=abs(a.y-b.y),disy=abs(a.x-b.x),然后即可以通过一条边计算它左右两个正方形。具体见代码。

3.最后去重,因为一个四边形,它的四条边都计算过它一次,因此将最后的结果/4。
 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std; bool vis[][];
//把所有值都加100 struct node
{
int x,y;
}point[]; bool cmp(node a,node b)
{
return a.x<b.x;
} bool judge(node c)
{
if(c.x>=&&c.x<=&&c.y>=&&c.y<=)
if(vis[c.x][c.y])
return true;
return false;
} int main()
{
int n,cnt;
while(~scanf("%d",&n))
{
memset(vis,false,sizeof(vis));
for(int i=;i<n;i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
point[i].x+=;
point[i].y+=;
vis[point[i].x][point[i].y]=true;
}
sort(point,point+n,cmp);
cnt=;
node a,b,c,d;
int disx,disy;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
a=point[i];
b=point[j];
disx=abs(a.y-b.y);
disy=abs(a.x-b.x);
if(b.y<=a.y)
{
//右上
c.x=b.x+disx;
c.y=b.y+disy;
d.x=a.x+disx;
d.y=a.y+disy;
if(judge(c)&&judge(d))
cnt++;
//左下
c.x=b.x-disx;
c.y=b.y-disy;
d.x=a.x-disx;
d.y=a.y-disy;
if(judge(c)&&judge(d))
cnt++;
}
else
{
//右下
c.x=b.x+disx;
c.y=b.y-disy;
d.x=a.x+disx;
d.y=a.y-disy;
if(judge(c)&&judge(d))
cnt++;
//左上
c.x=b.x-disx;
c.y=b.y+disy;
d.x=a.x-disx;
d.y=a.y+disy;
if(judge(c)&&judge(d))
cnt++;
}
}
}
printf("%d\n",cnt/);
}
return ;
}
           

HDU 6055 17多校 Regular polygon(计算几何)的更多相关文章

  1. HDU6055 Regular polygon(计算几何)

    Description On a two-dimensional plane, give you n integer points. Your task is to figure out how ma ...

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

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

  3. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  4. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

  5. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  6. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...

  7. HDU 3130 17多校7 Kolakoski(思维简单)

    Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...

  8. HDU 6038 17多校1 Function(找循环节/环)

    Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...

  9. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

随机推荐

  1. ubuntu开启慢日志

    ubuntu 开启mysql日志记录 1.找到mysql的配置文件sudo vim /etc/mysql/my.cnf将下面两行的#去掉#general_log_file = /var/log/mys ...

  2. JedisClusterMaxRedirectionsException: Too many Cluster redirections

    发生环境 当时的redis集群配置:redis-trib.rb 127.0.0.1 .... redis.conf的bind是默认# 解决方案 将redis.conf的bind为局域网真实ip red ...

  3. myeclipse debug模式 报错source not found

    myeclipse debug模式下,启动报错 source not found:SignatureParser.current() line: 解决方法:将debug视图下的右上方的jar有断点的地 ...

  4. [转载]Python3编码问题详解

    原文:Python3的编码问题 Python3 最重要的一项改进之一就是解决了 Python2 中字符串与字符编码遗留下来的这个大坑.Python 编码为什么那么蛋疼?已经介绍过 Python2 字符 ...

  5. 二十二、Spring MVC与Structs2的区别总结

    一.框架的入口 1.Structs2采用Filter(StructsPrepartAndExecuteFilter)来进行实现. 2.SpringMVC采用Servlet(DispatcherServ ...

  6. mybatis与spring的整合(代码实现)

    mybatis与spring的整合(代码实现) 需要jar包: mybatis核心包:依赖包:log4j包:spring croe;beans;tx;aop;aspects;context;expre ...

  7. tp5消息队列使用

    composer 安装 扩展包 composer require topthink/think-queue 注意版本:默认安装5.1的扩展包 地址: https://packagist.org/pac ...

  8. ActiveMQ 的线程池

    ActiveMQ 的线程池实质上也是 ThreadPoolExecutor,不过它的任务模型有自己的特点,我们先看一个例子: public static void main(String[] args ...

  9. Python学习之路【第三篇】--集合

    语法结构: set1.issubset(set2)判断集合set1是否为set2的子集,返回布尔值. ? 1 2 3 4 5 6 s1 = {'Java', 'PHP', 'Python', 'C++ ...

  10. 通过JdbcTemplate编写数据访问(二十八)

    数据源配置 在我们访问数据库的时候,需要先配置一个数据源,下面分别介绍一下几种不同的数据库配置方式. 首先,为了连接数据库需要引入jdbc支持,在pom.xml中引入如下配置: 1 2 3 4 < ...