Regular polygon
URL: http://acm.hdu.edu.cn/showproblem.php?pid=6055
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 86 Accepted Submission(s): 31
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
题解
其实知道两个点,另外两个点就确定了,枚举两个点即可 o(n2)
#include<stdio.h>
#include<string.h>
const int MAXN = 250;
int num[MAXN][MAXN],n;
struct node{int x, y;} dat[650];
int main()
{
while(scanf("%d", &n)!=EOF){
memset(num, 0 ,sizeof(num));
for(int i = 0; i < n; ++i) {
int X, Y;
scanf("%d%d", &X, &Y);
X += 110;
Y += 110;
++num[X][Y];
dat[i].x = X;
dat[i].y = Y;
}
int ans = 0;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
int t1 = 0, t2 = 0;
int x1 = dat[j].x - dat[j].y + dat[i].y;
int y1 = dat[j].y + dat[j].x - dat[i].x;
int x2 = dat[j].x - dat[j].y + dat[i].y - dat[j].x + dat[i].x;
int y2 = dat[j].y + dat[j].x - dat[i].x - dat[j].y + dat[i].y;
if(0 < x1 && x1 < MAXN && 0 < y1 && y1 < MAXN && 0 < x2 && x2 < MAXN && 0 < y2 && y2 < MAXN)
t1 = num[dat[i].x][dat[i].y] && num[dat[j].x][dat[j].y] && num[x1][y1] && num[x2][y2];
x1 = dat[j].x + dat[j].y - dat[i].y;
y1 = dat[j].y - dat[j].x + dat[i].x;
x2 = dat[j].x + dat[j].y - dat[i].y - dat[j].x + dat[i].x;
y2 = dat[j].y - dat[j].x + dat[i].x - dat[j].y + dat[i].y;
if(0 < x1 && x1 < MAXN && 0 < y1 && y1 < MAXN && 0 < x2 && x2 < MAXN && 0 < y2 && y2 < MAXN)
t2 = num[dat[i].x][dat[i].y] && num[dat[j].x][dat[j].y] && num[x1][y1] && num[x2][y2];
if(t1) ++ans;
if(t2) ++ans;
}
}
printf("%d\n",ans/4);
}
return 0;
}