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. hadoopMR自定义输入类型

    hadoop中的输入输出数据类型: BooleanWritable:标准布尔型数值 ByteWritable:单字节数值 DoubleWritable:双字节数值 FloatWritable:浮点数 ...

  2. Codeforces Round #525 (Div. 2)-A/B/C/E

    http://codeforces.com/contest/1088/problem/A 暴力一波就好了. //题解有O(1)做法是 (n-n%2,2) #include<iostream> ...

  3. Ubuntu 14.04(64位)+GTX970+CUDA8.0+Tensorflow配置 (双显卡NVIDIA+Intel集成显卡) ------本内容是长时间的积累,有时间再详细整理

    (后面内容是本人初次玩GPU时,遇到很多坑的问题总结及尝试解决办法.由于买独立的GPU安装会涉及到设备的兼容问题,这里建议还是购买GPU一体机(比如https://item.jd.com/396477 ...

  4. Java Code Examples for org.codehaus.jackson.map.DeserializationConfig 配置

    The following code examples are extracted from open source projects. You can click  to vote up the e ...

  5. matlab plot line settings

  6. mysql 语句根据身份证查询年龄,地址,性别

    select  case left(idcard,2) when '11' then '北京市'when '12' then '天津市'when '13' then '河北省'when '14' th ...

  7. java 一些容易忽视的小点-数据类型和运算符篇

    注释 文档注释:   以"/**"开头以"*/"结尾,注释中包含一些说明性的文字及一些JavaDoc标签(后期写项目时,可以生成项目的API) 行注释:   以 ...

  8. js 敏感词过滤

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. Mysql InnoDB三大特性-- 自适应hash index

    Mysql InnoDB三大特性-- 自适应hash index

  10. Saiku连接mysql数据库(二)

    Saiku连接Mysql数据库展示数据 参考链接:https://www.cnblogs.com/shirui/p/8573491.html 官方文档:https://media.readthedoc ...