Computational Geometry problems


CodeForces1096 C. Polygon for the Angle

Meaning of the questions:

Given an angle The
required output a minimum of n, n-gon satisfied, it is possible to select three vertices, the vertex lines of the three corners formed angle equal to, if there is no output is -1.
If ensure a solution, the solution is not more than 998,244,353
Data range: 1 <= angle <180
example:
54 degrees, 10 may be configured gon
Here Insert Picture Description

Ideas:

Here Insert Picture Description
The yellow three corners of the same angle, proved:
first draw circumcircle is the circumferential angle of the three corners, the presence theorem: a circumferential angle of which number is equal to half the number of the circular arc corresponding to the center angle of
the polygon is positive polygonal, arcuate so that three angles are of equal length, and therefore the same center angles of the three corners of the number, the same number of circumferential angle

Obviously yellow minimum angle is the angle of the polygon can be constructed, and
can be found: as long as the multiple of the minimum angle, the maximum angle of not more than the polygon (i.e. inner angle), then the polygon can be constructed
n-gon interior angle formula : 180 (n-2) / n
minimum angle calculation : calculating first central angle corresponding to the minimum angle, then dividing by 2, and easy to derive the internal angle of the central angle = 180,
may be pushed so that: n-2 was found smallest angle may be comprised of an interior angle, the minimum interior angle = angle / (n-2), in conjunction with interior angles formula find the minimum angle = 180 / n

Try biggest hit list n is the number, and then judge for themselves whether the violence.
N = 360 found playing table when the angle can be 1 to 179 all represented.
Thus the pre n = 3 to n = 360 can be constructed out of all the angles and the playing table for each interrogation O (1) to the output

code:

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;
map<int,int>mark;
signed main(){
    for(int i=3;;i++){
        double mi=180.0/i;//记得用180.0而不是180
        for(int j=1;j<=i-2;j++){
            double t=mi*j;
            int tt=(int)t;
            if(t-tt<=eps&&!mark[tt]){
                mark[tt]=i;
            }
        }
        if(mark.size()==179){
            break;
        }
    }
    int T;
    cin>>T;
    while(T--){
        int angle;
        cin>>angle;
        cout<<mark[angle]<<endl;
    }
    return 0;
}

Published 430 original articles · won praise 36 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_44178736/article/details/104811067