Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2219    Accepted Submission(s): 880

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个点,问总共能形成多少个正多边形。

思路:实际上只能形成正四边形,在官方题解里给出了相关的论文。。。然后就变成了一道水题,暴力枚举点对,查找每个点对是否有对应的点对形成正方形。由于坐标存在负数,对输入数据做一下处理,以及注意横(纵)坐标差值<=200,注意到这两点基本没问题了。具体看代码。

AC代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
struct Node{
int x;
int y;
}node[];
bool vis[][];
int main()
{
int n,dx,dy,a,b;
while(~scanf("%d", &n))
{
int res=;
memset(vis, , sizeof(vis));
for(int i=;i<n;i++){
scanf("%d%d", &a, &b);
a+=;
b+=;
node[i].x=a;
node[i].y=b;
vis[node[i].x][node[i].y]=;
} for(int i=;i<n;i++)
for(int j=i+;j<n;j++){
dx=node[i].x-node[j].x;
dy=node[i].y-node[j].y;
if(vis[node[i].x+dy][node[i].y-dx]==&&vis[node[j].x+dy][node[j].y-dx]==)
res++;
if(vis[node[i].x-dy][node[i].y+dx]==&&vis[node[j].x-dy][node[j].y+dx]==)
res++; }
cout<<res/<<endl;
}
}

最新文章

  1. PMO是什么?如何与其他部门协作配合提高项目成功率?
  2. js 字符串的操作
  3. JS魔法堂:jsDeferred源码剖析
  4. WEB前端开发学习:源码canvas 雪
  5. Android课程---Activity的创建
  6. 【LeetCode OJ】Convert Sorted Array to Binary Search Tree
  7. 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样)
  8. Windows程序消息机制浅析
  9. MySQL的记录长度
  10. POJ1838
  11. android背景平铺方式 tileMode
  12. PHP进度条
  13. poj 4982 踩方格
  14. 【新提醒】N820 N821 android 4.2 V1.1版 - 大V综合交流区 - 360官方论坛
  15. c2d遮罩
  16. 类加载(四):spring-boot-loader 模块
  17. SGU 271 Book Pile
  18. 第一次java测试有感
  19. UVA 11019 Matrix Matcher(哈希)
  20. Oracle 学习之exists

热门文章

  1. mysql_DML_select_聚合join
  2. 《图解设计模式》读书笔记2-2 Factory Method模式
  3. vue.js + element 搭建后台管理系统 笔记(一)
  4. Xpath表达式的粗介绍
  5. 编程语言 - 大数据 - Hadoop
  6. Pikachu漏洞练习平台实验——php反序列化、XXE、SSRF(九)
  7. PHP_CodeIgniter 细节
  8. manacher算法学习(求最长回文子串长度)
  9. P3826 [NOI2017]蔬菜
  10. k8s nginx ingress配置TLS