Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1892 Accepted Submission(s): 743
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
题意:正方形,在二维平面给你若干个点,问有多少个正方组合?
由于给的数均是整数,因此能判定只要给出两个点就能判断是否存在正方形:
取x1,y1;x2,y2两个点,我们能这样计算出x3,y3;,x4,y4两个点,只有存在这两个点才能组成正方形。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
int check(int x1,int y1)
{
if(x1>=0&&x1<=200&&y1>=0&&y1<=200)
return 1;
return 0;
}
struct node
{
int x,y;
}point[550];
int main()
{
int n;
int vist[210][210];
while(scanf("%d",&n)!=EOF)
{
memset(vist,0,sizeof(vist));
for(int i=0;i<n;i++)
{
scanf("%d %d",&point[i].x,&point[i].y);
point[i].x+=100;
point[i].y+=100;
vist[point[i].x][point[i].y]=1;
}
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
//if(i==j)continue;
int x1=point[i].x;
int y1=point[i].y;
int x2=point[j].x;
int y2=point[j].y;
int x3=x1+(y1-y2);
int y3= y1-(x1-x2);
int x4=x2+(y1-y2);
int y4= y2-(x1-x2);
if(check(x3,y3)&&check(x4,y4)&&vist[x3][y3]&&vist[x4][y4])
{
ans++;
}
x3=x1-(y1-y2);
y3= y1+(x1-x2);
x4=x2-(y1-y2);
y4= y2+(x1-x2);
if(check(x3,y3)&&check(x4,y4)&&vist[x3][y3]&&vist[x4][y4])
{
ans++;
}
}
}
cout<<ans/4<<endl;
}
return 0;
}