hdu6055 Regular polygon 2017多校联盟2 11题 -枚举

来源:互联网 发布:国产电视知乎 编辑:程序博客网 时间:2024/06/05 06:04

Regular polygon

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


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




/*题意:n个点,确定这n个点能组成几个正多边形题解:只有正四边形可以使得所有的顶点为整数点.(具体证明可参考杨景钦在2017的国家队论文)所以正解即求出所有的正四边形个数。枚举2个点,然后暴力判断另外2个点的位置是否存在。最后因为以每个正方形的每一条边为基础找另外两个点,所以每个正方形共计算了4次,ans/=4*/#include <iostream>#include <cstdio>#include <algorithm>#include <string.h>#include <stdlib.h>#include <set>#include <algorithm>#include <vector>#include <queue>using namespace std;const int maxn = 500+10;const int mod = 1e9+7;struct data{    int x;    int y;};data a[maxn];bool vis[maxn][maxn];int f(data a,data b){    int cnt = 0;    int x = a.x-b.x;    int y = a.y-b.y;    if(a.x+y>=0 && a.y-x>=0 && b.x+y>=0 && b.y-x>=0 && vis[a.x+y][a.y-x] && vis[b.x+y][b.y-x])        cnt++;    if(a.x-y>=0 && a.y+x>=0 && b.x-y>=0 && b.y+x>=0 && vis[a.x-y][a.y+x] && vis[b.x-y][b.y+x])        cnt++;    return cnt;}int main(){    int n;    while(scanf("%d",&n)!=EOF){        memset(vis,0,sizeof(vis));        for(int i = 0; i<n;++i){            scanf("%d%d",&a[i].x,&a[i].y);            a[i].x+=200;            a[i].y+=200;            vis[a[i].x][a[i].y] = 1;        }        int ans = 0;        for(int i = 0;i<n;++i){            for(int j = i+1;j<n;++j){                ans += f(a[i],a[j]);            }        }        printf("%d\n",ans/4);    }    return 0;}

 
原创粉丝点击