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. python-day97--django-ModelForm

    Model Form :直接利用你的models里的字段 应用场景: - ModelForm - 中小型应用程序(model是你自己写的) - Form - 大型应用程序 注意事项: - 1. 类 f ...

  2. Django之信号和序列化

    前言 Django的信号要从一张抽象图和一个需求说起: 赛道:Django 赛车:http请求 基础设施:Django设置的信号 一.Django内置信号类型 1.既然赛道上有各种基础设置,那么Dja ...

  3. PowerShell使用教程

    一.说明 1.1 背景说明 个人对PowerShell也不是很熟悉,开始的时候就突然看到开始菜单中多了个叫PowerShell的文件夹,后来一点就看到某个教程视频说PowerShell很厉害但也没怎么 ...

  4. weblogic查看版本号教程

    1.查看软件版本号 cd /weblogic/bea/wlserver_10.3/server/lib java -cp weblogic.jar weblogic.version 说明:版本号后边的 ...

  5. 码云git使用三(本地代码合并)

    现在我们已经学会了把“本地代码上传至码云git服务器”和“从码云git服务器下载代码到本地”. 我们现在学习怎么上传代码到服务器注意事项和步骤. 1.我们修改代码后,我们需要先+Add后再Commit ...

  6. JAVA8的LocalDateTime使用心得和工具类

    今天做不成的事,明天也不会做好. 同学们,JAVA8出了这么久,不知道你们有没有用过它的LocalDateTime类型,还是依然用Date类型呢?其实,LocalDateTime类型给我们提供了很多便 ...

  7. 顺序容器----顺序容器操作,vector对象如何增长,额外的string操作,容器适配器

    一.顺序容器操作 1.向顺序容器添加元素 向顺序容器(array除外)添加元素的操作: 操作 说明 c.push_back(t) 在c的尾部创建一个值为t的元素.返回void c.emplace_ba ...

  8. laravel中db获取某个数据的具体字段值:

    $helpfriend = DB::connection('luckyrecord')->table($luckyrecord)->where('id', $luckyrecordid)- ...

  9. API服务网关(Zuul)

    技术背景 前面我们通过Ribbon或Feign实现了微服务之间的调用和负载均衡,那我们的各种微服务又要如何提供给外部应用调用呢. 当然,因为是REST API接口,外部客户端直接调用各个微服务是没有问 ...

  10. Java使用wait() notify()方法操作共享资源

    Java多个线程共享资源: 1)wait().notify()和notifyAll()方法是本地方法,并且为final方法,无法被重写. 2)调用某个对象的wait()方法能让当前线程阻塞,并且当前线 ...