Educational Codeforces Round 57 (Rated for Div. 2) C. Polygon for the Angle 数学

C. Polygon for the Angle

在这里插入图片描述

solution

1 < a n g < 180 , 预 处 理 1 至 360 边 形 的 单 位 角 度 即 可 1<ang<180,预处理1至360边形的单位角度即可 1<ang<1801360

code

/*Siberian Squirrel*/
/*Cute JinFish*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const double PI = acos(-1), eps = 1e-8;
/*const int MOD = 998244353, r = 119, k = 23, g = 3;
const int MOD = 1004535809, r = 479, k = 21, g = 3;*/
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int M = 1e7 + 10, N= 2e6 + 10;

int sgn(double x) {
    
    
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
//inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
//double Rand() {return (double)rand() / RAND_MAX;}

ll n;
double f[400];

void init() {
    
    
    for(int i = 1; i <= 360; ++ i) {
    
    
        f[i] = (i - 2.0) * 180 / i;
    }
}

void solve(ll res = 0) {
    
    
    for(int i = 1; i <= 360; ++ i) {
    
    
        for(int j = 1; (180 - f[i]) / 2.0 * j <= f[i]; j++) {
    
    
            if(!sgn((180 - f[i]) / 2.0 * j - n)) {
    
    
                cout << i << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}


int main() {
    
    
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(nullptr);
// srand(time(0));
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    init();
    int o = 1;
	cin >> o;
    while(o --) {
    
    
        cin >> n;
        solve();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46173805/article/details/115084887