HDU-6055-Regular polygon

来源:互联网 发布:妲己 女娲 知乎 编辑:程序博客网 时间:2024/05/01 17:53

Regular polygon

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


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
 

Source
2017 Multi-University Training Contest - Team 2
 

解题代码
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;struct node{    int x,y;}ch[505];int vis[205][205];int main(){    int N;    while(scanf("%d",&N)!=EOF)    {        memset(vis,0,sizeof(vis));        for(int i=1;i<=N;i++)        {            scanf("%d%d",&ch[i].x,&ch[i].y);            ch[i].x+=100;            ch[i].y+=100;            vis[ch[i].x][ch[i].y]=1;        }        int count1=0;        for(int i=1;i<=N;i++)            for(int j=i+1;j<=N;j++)        {            int x1=ch[i].x;            int y1=ch[i].y;            int x2=ch[j].x;            int y2=ch[j].y;            int dx=ch[i].x-ch[j].x;            int dy=ch[i].y-ch[j].y;            if(x1+dy>=0&&x1+dy<=200&&y1-dx>=0&&y1-dx<=200&&x2+dy>=0&&x2+dy<=200&&y2-dx>=0&&y2-dx<=200)            {                if(vis[x1+dy][y1-dx]==1&&vis[x2+dy][y2-dx]==1)                    count1++;            }            if(x1-dy>=0&&x1-dy<=200&&y1+dx>=0&&y1+dx<=200&&x2-dy>=0&&x2-dy<=200&&y2+dx>=0&&y2+dx<=200)            {                if(vis[x1-dy][y1+dx]==1&&vis[x2-dy][y2+dx]==1)                    count1++;            }        }        printf("%d\n",count1/4);    }    return 0;}


原创粉丝点击