17多校contest two 1011Regular polygon ( 计算几何

来源:互联网 发布:环形网络拓扑结构 编辑:程序博客网 时间:2024/05/18 00:15

Regular polygon

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

题意

平面上给一组坐标 判断一共可以组成多少个正多边型

题解:

这个道题完全是靠结论的好不 唉
坐标为整数的点 所组成的正多边形 一定是正方形
那么就是已知两个点 枚举另外两个点(两个点可以决定2个正方形
已知(x1,x2) (y1,y2)

x3=x1+(y1-y2) y3= y1-(x1-x2)

x4=x2+(y1-y2) y4= y2-(x1-x2)

x3=x1-(y1-y2) y3= y1+(x1-x2)

x4=x2-(y1-y2) y4= y2+(x1-x2)

AC代码

#include <bits/stdc++.h>using namespace std;#define LL long long#define CLR(a,b) memset(a,(b),sizeof(a))const int N = 500+10;bool vis[N<<1][N<<1];int X[N], Y[N];int main(){    int n;    while(~scanf("%d",&n)) {        CLR(vis,false);        LL k = 0;        for(int i = 0; i < n; i++) {            scanf("%d%d",&X[i],&Y[i]);            vis[N+X[i]][N+Y[i]] = true;        }        int x1, x2, x3,         x4;        int y1, y2, y3, y4;        for(int i = 1; i < n; i++) {            x1 = X[i], y1 = Y[i];            for(int j = 0; j < i; j++) {                x2 = X[j], y2 = Y[j];                x3 = x1 + (y1-y2);                y3 = y1 - (x1-x2);                x4 = x2 + (y1-y2);                y4 = y2 - (x1-x2);                if(vis[N+x3][N+y3] && vis[N+x4][N+y4]) k++;                x3 = x1 - (y1-y2);                y3 = y1 + (x1-x2);                x4 = x2 - (y1-y2);                y4 = y2 + (x1-x2);                if(vis[N+x3][N+y3] && vis[N+x4][N+y4]) k++;            }        }        printf("%lld\n",k/4);    }return 0;}
原创粉丝点击