2017多校2 1011 Regular polygon

来源:互联网 发布:西安java培训多少钱 编辑:程序博客网 时间:2024/06/06 15:35

Regular polygon

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


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个整数点的坐标,问能组成多少个不同的正多边形
很显眼因为是整数点,那就只能组成正方形了,思路是枚举2个点,然后把能组成正方形的另外2个点的坐标求出来,询问这两个点是否存在。因为坐标存在负值,所以不能单纯的用数组去记录,可以将整张图向右上角挪300个位置,将负点放到第一象限去,就可以开数组记录了。也可以利用点到原点的距离这一特征来构建哈希表来存点。





#include<iostream>#include<cmath>#include<cstdio>#include<cstring>using namespace std;struct node{    int x;    int y;    int next;}edge[5555];int head[55555];long long int ans=0;int co;int x[5555];int y[5555];void insert(int x,int y){    int l=(x*x+y*y)%10007;    edge[co].x=x;    edge[co].y=y;    edge[co].next=head[l];    head[l]=co;    co++;}void inti(){    for(int i=0;i<=11111;i++)    head[i]=-1;    ans=co=0;}bool find(int x,int y){    int l=(x*x+y*y)%10007;      int next;      next=head[l];      while(next!=-1)      {          if (x==edge[next].x&&y==edge[next].y) return 1;          next=edge[next].next;      }      return 0; }int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int i,j;        int xx,yy;         inti();        for(i=1;i<=n;i++)        {            scanf("%d%d",&x[i],&y[i]);            insert(x[i],y[i]);        }        for (i=1;i<=n;++i)          {              for (j=i+1;j<=n;++j)              {                  int x1=x[i]-(y[i]-y[j]);                  int y1=y[i]+(x[i]-x[j]);                  int x2=x[j]-(y[i]-y[j]);                  int y2=y[j]+(x[i]-x[j]);                 if (find(x1,y1)&&find(x2,y2))++ans;              }          }         for (i=1;i<=n;++i)          {              for (j=i+1;j<=n;++j)              {                  int x1=x[i]+(y[i]-y[j]);                  int y1=y[i]-(x[i]-x[j]);                  int x2=x[j]+(y[i]-y[j]);                  int y2=y[j]-(x[i]-x[j]);                 if (find(x1,y1)&&find(x2,y2))++ans;              }          }          ans=ans/4;        cout<<ans<<endl;    }    return 0;}