【Codeforces Round 57 (Rated for Div. 2)】Polygon for the Angle
【Codeforces Round 57 (Rated for Div. 2)】Polygon for the Angle
题意:给出一个角度,找出一个最小的正多边形,使得某三个顶点连成的角等于已给角度,输出这个正多边形

思路:每一个正多边形都有他的外接圆和内切圆,并且两个圆的圆心是相同的
圆心角是圆周角的二倍,圆心角从 360/n 开始取值,一直取到(n-2)× (360/n)
注意179度是可以由360边形构造出来的

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
#define eps 0.001
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define memset(a,b) memset(a,b,sizeof(a))
const int MAX=3e5+10;
int a[190];
void init()
{
    for(int i=3;i<=360;i++){
        if(360 % i != 0)
            continue;
        int s = 360 / i;
        for(int j=1;j<=i-2;j++){
            if((s*j)%2!=0)
               continue;
            if(a[s*j/2] == 0)
                a[s*j/2] = i;
        }
    }
    return ;
}
int main()
{
    memset(a,0);
    init();
    int T,n;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        if(a[n] == 0)
            printf("-1\n");
        else
            printf("%d\n",a[n]);
    }
    return 0;
}

相关文章:

  • 2021-05-17
  • 2021-09-25
  • 2022-03-02
  • 2022-01-01
  • 2021-05-17
猜你喜欢
  • 2022-01-15
  • 2021-07-11
  • 2021-11-09
  • 2022-12-23
  • 2021-05-25
  • 2021-12-23
相关资源
相似解决方案