HDU 6055 (2017 多校训练赛2 1011)Regular polygon

来源:互联网 发布:linux 查找文件关键字 编辑:程序博客网 时间:2024/06/16 19:03

2017 Multi-University Training Contest - Team 2 1011

Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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
40 00 11 01 160 00 11 01 12 02 1
 

Sample Output
12
 

题意:
给出n个点坐标,问能组成多少个正多边形

分析:
因为题目说坐标点都为整数且范围在(-100,100) 内
所以只有正方形满足这个条件。
那么问题转化为判断能组成多少个正方形

因为数据量很小,直接枚举就好啦
枚举两个点,算出他们的向量,然后去查找是否存在组成正方形的点,
结果除4

AC代码:
#include<stdio.h>#include<algorithm>#include<string.h>int aim[500][500];struct Point{    int x,y;}p[555];int solve(Point a,Point b){    int x=a.x-b.x;    int y=a.y-b.y;    int ans=0;    if(a.x+y>=0&&a.y-x>=0&&b.x+y>=0&&b.y-x>=0&&aim[a.x+y][a.y-x]&&aim[b.x+y][b.y-x])    ans++;    if(a.x-y>=0&&a.y+x>=0&&b.x-y>=0&&b.y+x>=0&&aim[a.x-y][a.y+x]&&aim[b.x-y][b.y+x])    ans++;    return ans;}int main(){    int n;    while(scanf("%d",&n)==1)    {        memset(aim,0,sizeof(aim));        for(int i=0;i<n;i++)        {            int a,b;            scanf("%d%d",&a,&b);            a+=200;b+=200;            p[i].x=a;            p[i].y=b;            aim[a][b]=1;        }        int ans=0;        for(int i=0;i<n;i++)        {            for(int j=i+1;j<n;j++)            {                if(i!=j)                ans+=solve(p[i],p[j]);            }        }        printf("%d\n",ans/4);    }}



原创粉丝点击