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

【HDU 6055 Regular polygon】+ map

2017-07-27 17:28 302 查看
Regular polygon

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

Total Submission(s): 42 Accepted Submission(s): 13

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

Source

2017 Multi-University Training Contest - Team 2

思路 : 暴力两个点,map 判断剩下两个点是否存在

AC代码:

#include "cstdio"
#include "map"
#include "cstring"
using namespace std;
struct Point{
int x,y;
}point[510];
int Map[700][700];
int main(){
int n;
while(~scanf("%d",&n)){
memset(Map, 0, sizeof(Map));
for(int i=1;i<=n;i++){
scanf("%d %d",&point[i].x,&point[i].y);
Map[point[i].x+300][point[i].y+300]=1;
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==j) continue;
double a = point[i].x,b = point[i].y;
double c = point[j].x,d = point[j].y;
double xi1= (a+b+c-d)/2.0;
double yi1= (-a+b+c+d)/2.0;
double xi2= (a-b+c+d)/2.0;
double yi2= (a+b-c+d)/2.0;
int x1 = xi1,y1=yi1,x2=xi2,y2=yi2;
if(Map[x1+300][y1+300]&&Map[x2+300][y2+300]&&x1==xi1&&y1==yi1&&x2==xi2&&y2==yi2){
ans++;
}
}
}
printf("%d\n",ans/4);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: