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. idea live template高级知识, 进阶(给方法,类,js方法添加注释)(二)

    上一篇文章(http://www.cnblogs.com/xzjxylophone/p/6994488.html) 是在 groovyScript中直接添加的代码,这个看起来是简单,粗暴,麻烦和不美观 ...

  2. 使用awk进行日志信息的分组统计

    起因 这是今天我线上出了一个bug,需要查看日志并统计一个我需要的信息出现的频率,可以叫做分组统计. 日志文件部分内容 00:09:07.655 [showcase_backend][topsdk] ...

  3. 【LeetCode】49. Group Anagrams

    题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...

  4. PHP实现简单的评论与回复功能还有删除信息

    我们首先先看一下功能 上面黑色的是评论的下面红色的字体是回复的 再来看看怎么实现的 1.发布评论 <form action="pinglunchili.php" method ...

  5. ASP.NET Core 2.0 SignalR 示例

    # 一.前言 上次讲SignalR还是在<[在ASP.NET Core下使用SignalR技术](http://dotnet.ren/2017/02/21/%E5%9C%A8ASP-NET-Co ...

  6. 关于标签中常用的disabled

    .children("option[disabled]").removeAttr('disabled');

  7. UGUI射线检测

    1.Graphic Raycaster 主要用于UI上的射线检测,挂有这个组件的物体,必须要挂上Canvas这个组件(当挂上Graphic Raycaster时Canvas也会自动挂上). Ignor ...

  8. 判断DataRow中是否包含某列

    DataRow dr = new DataRow(); if (dr!=null && dr.Table.Columns.Contains("errormesg") ...

  9. 一步一步学Vue (一)

    vue应该是前端主流框架中的集成大成者,它吸取了knockout,angular,react设置avalon的经验,支持各种模式写法,入门很简单,从本章开始,会记录学习vue中的点点滴滴,以笔记的形式 ...

  10. String to Integer (atoi) - 字符串转为整形,atoi 函数(Java )

    String to Integer (atoi) Implement atoi to convert a string to an integer. [函数说明]atoi() 函数会扫描 str 字符 ...