Codeforces:C. Polygon for the Angle

C. Polygon for the Angle

time limit per test 2 seconds
memory limit per test 256 megabytes

Problem Decription

You are given an angle ang.The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with ∠abc=ang or report that there is no such n-gon.
在这里插入图片描述
If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn’t exceed 998244353.

Input

The first line contains single integer T
(1≤T≤180) — the number of queries.

Each of the next T lines contains one integer ang (1≤ang<180) — the angle measured in degrees.

Output

For each query print single integer n(3≤n≤998244353) — minimal possible number of vertices in the regular n-gon or −1 if there is no such n.

Example

Input
4
54
50
2
178
Output
10
18
90
180

Note

The answer for the first query is on the picture above.

The answer for the second query is reached on a regular 18-gon. For example, ∠v2v1v6=50∘.

The example angle for the third query is ∠v1v0v2=2.

In the fourth query, minimal possible n is 180 (not 90).

解题心得:

  1. 很简单的一个计算几何,初看起来有点蒙,但是在这个正多边形的外面添加一个外接圆就很简单了。
    在这里插入图片描述
  2. 在这里主要需要得到两个角,多边形的一个内角,以及一个最小弧对应的角。根据等弧对等角可以得知,任选三点得到的角一定是最小角的倍数。一个内角如图就是<Y的二倍,2 × <Y = 180 - 360/n 这样可以得到一个内角。然后(假设图上对应的是一个最小弧)最小角就是<R/2,即 <Y/2 = 180 - 内角 / 2。
  3. 最后在打表的时候要注意任选三点得到的一个角不能大于其内角,就是样例的最后一个。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;

struct Ang {
    double a, b;
}ang[maxn];

void pre_deal() {
    ang[3].b = ang[3].a = 60;
    for(int i=4;i<=360;i++) {
        ang[i].a = 180 - (double)360/i;
        ang[i].b = (double)(180 - ang[i].a)/2.0;
    }
}

int query(int x) {
    for(int i=3;i<=360;i++) {
        for(double j=ang[i].b;j<=360 && j<= ang[i].a; j+= ang[i].b) {
            if(j == x) return i;
        }
    }
    return -1;
}

int main() {
    //freopen("1.in", "r", stdin);
    pre_deal();
    int t; scanf("%d", &t);
    while(t--) {
        int que; scanf("%d", &que);
        printf("%d\n", query(que));
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值