hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest

来源:互联网 发布:js object添加元素 编辑:程序博客网 时间:2024/06/05 18:44

Regular polygon

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

官方题解:
这里写图片描述

代码:

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1000+5;struct point{    int x,y;    point() {}    point(int a,int b)    {        x=a,y=b;    }} pt[maxn];int vis[maxn][maxn];int n;point solve(point p1,point p2){    int tx=p2.x-p1.x;    int ty=p2.y-p1.y;    return point(p1.x-ty,p1.y+tx);}int main(){    while(~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        for(int i=0; i<n; ++i)        {            scanf("%d%d",&pt[i].x,&pt[i].y);            pt[i].x+=400;            pt[i].y+=400;            vis[pt[i].x][pt[i].y]=1;        }        int ans=0;        for(int i=0; i<n; ++i)            for(int j=0; j<n; ++j)            {                if(i==j)                    continue;                point p1=solve(pt[i],pt[j]);                if(!vis[p1.x][p1.y])                    continue;                point p2=solve(p1,pt[i]);                if(vis[p2.x][p2.y])                    ++ans;            }        printf("%d\n",ans/4);    }    return 0;}



ps:这种判断正方形的方法也是一种套路。。

阅读全文
2 0
原创粉丝点击