Regular Polygon - UVa 10824 几何+二分

Regular Polygon
Input: 
Standard Input

Output: Standard Output

 

A regular polygon is an n-sided polygon in which the sides are all the same length and are symmetrically placed about a common center (i.e., the polygon is both equiangular and equilateral). Only certain regular polygons are "constructible" using the classical Greek tools of the compass and straightedge. The terms equilateral triangle and square refer to the regular 3- and 4-polygons, respectively.  The picture below shows some regular polygons with different number of sides:

 


Given N(0<N≤2000) points on a particular circle, your job is to find out how many regular polygons of different number of edges are formed by these points. For example if you are given 100 points, then these 100 points will form a regular hexagon if six of these 100 points are the vertices of a regular hexagon.

Input

The input file contains at most 10 sets of inputs. The description of each set is given below. The input file contains at most 20000 lines in total.

The first line of each set is an integer N(0<N≤2000) which indicates how many points are there in this set. Each of the next N lines contains two floating-point numbers, which is the Cartesian coordinate of a point (Accurate to at least nine decimal places). You can assume that all the points lie on the same circle, the center of this circle is the origin, and the coordinate of any two points will not be the same. Also assume that two points are same if their angular distance with respect to the centre of the circle is less than 10-8 radian.

 

Input is terminated by a set where the value of N is zero. This set should not be processed.

 

Output

For each set of input produce one or more lines of output. First line of the output for each set contains the serial of output as shown in the output for sample input. Each of the next few lines will contain two integers S and F, where S denotes the number of sides of a regular polygon and F denotes how many times it is formed by the input points. These outputs should be sorted in ascending order of S. The regular polygons, which are not formed by the input points, should not be reported. For example, in case of the second sample input no regular pentagon (5-gon) is formed, so it is not reported in the output. 

 

 

 

Sample Input                                Output for Sample Input

5
-1000.0000000000 0.0000000000
-500.0000000000 866.0254037844
500.0000000000 866.0254037844
-500.0000000000 -866.0254037844
1000.0000000000 0.0000000000
6
-800.0000000000 0.0000000000
800.0000000000 0.0000000000
-400.0000000000 692.8203230276
400.0000000000 692.8203230276
400.0000000000 -692.8203230276
-400.0000000000 -692.8203230276

0

Case 1:
3 1
Case 2:
3 2
6 1

Problem setter: Shahriar Manzoor


题意:在一个圆上给你一些点,问你正K边形有多少个。另外两个点的弧度相差在1e-8内可以看成是相同的。

思路:枚举k边形,再枚举每个点,然后就是向后二分找有没有符合的点,每次扫到的点都标记一下,之后就不用再考虑了。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const double eps = 1e-8;
struct node
{ double x,y,atan;
}dian[2010];
bool cmp(node a,node b)
{ return a.atan<b.atan;
}
int n;
long long ans[2010];
double ang[2010],angle[2010],R,R2,vis[2010],pi=3.14159265358979;
int solve(double to)
{ int l=1,r=n,mi;
  while(l<r)
  { mi=(l+r)/2;
    if(dian[mi].atan>to-eps)
     r=mi;
    else
     l=mi+1;
  }
   return l;
}
int main()
{ int i,j,k,p,num,t=0,T=0,pos;
  double m,start,to;
  while(~scanf("%d",&n) && n)
  { memset(ans,0,sizeof(ans));
    for(i=1;i<=n;i++)
    { scanf("%lf%lf",&dian[i].x,&dian[i].y);
      dian[i].atan=atan2(dian[i].y,dian[i].x)+pi;
    }
    sort(dian+1,dian+1+n,cmp);
    for(k=3;k<=n;k++)
    { m=2*pi/k;num=0;
      T++;
      for(i=1;i<=n;i++)
       if(vis[i]!=T)
       { start=dian[i].atan;
         vis[i]=1;
         for(j=1;j<k;j++)
         { to=start+j*m;
           if(to>2*pi+eps)
            to-=2*pi;
           pos=solve(to);
           while(pos<=n && vis[pos]==T && to>dian[pos].atan-eps && to<dian[pos].atan+eps)
            pos++;
           if(to>dian[pos].atan-eps && to<dian[pos].atan+eps && vis[pos]!=T)
             vis[pos]=T;
           else
             break;
         }
         if(j==k)
          ans[k]++;
       }
    }
    printf("Case %d:\n",++t);
    for(k=3;k<=n;k++)
     if(ans[k]>0)
      printf("%d %lld\n",k,ans[k]);
  }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值