您的位置:首页 > 编程语言 > Go语言

HDU 6055 Regular polygon(几何)

2017-07-27 22:07 435 查看


Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 643    Accepted Submission(s): 232


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
4000

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

 

Source

2017 Multi-University Training Contest - Team 2 

 

题意:
给你n个点,问你可以确定几个不同的正多边形。

POINT:
一顿瞎猜成功知道了只有正方形的情况。之后反正只有500个点,就遍历2个点,可以确定2个正方形,看看另外2对顶点存不存在就行了,别忘记/8去重。
因为mp数组来记录地图上有没有点,并且把负点都加了200来变正,那么点在判断的时候其实会超出地图一倍。
比如(0,300)和(300,300) 你得判断(300,600)-(0,600)和(0,0)-(300,0)有没有点,所以数组要开大,干脆开一千。还有就是点为负的情况去掉,也会数组越界。上面的点都处理变正了,不需要考虑负点。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define LL long long
int mp[1000][1000];
int x[555],y[555];

int main()
{
int n;
while(~scanf("%d",&n))
{
memset(mp,0,sizeof mp);
for(int i=1;i<=n;i++)
{
scanf("%d %d",&x[i],&y[i]);
x[i]+=200,y[i]+=200;
mp[x[i]][y[i]]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) continue;
int a=x[i]-x[j];
int b=y[i]-y[j];
if(x[i]-b>=0&&y[i]+a>=0&&x[j]-b>=0&&y[j]+a>=0&&mp[x[i]-b][y[i]+a]&&mp[x[j]-b][y[j]+a])
{
ans++;
}
if(x[i]+b>=0&&y[i]-a>=0&&x[j]+b>=0&&y[j]-a>=0&&mp[x[i]+b][y[i]-a]&&mp[x[j]+b][y[j]-a])
ans++;
}
}
printf("%d\n",ans/8);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: