CF #421 B. Mister B and Angle in Polygon

来源:互联网 发布:文明6mac破解版 编辑:程序博客网 时间:2024/06/07 10:19
B. Mister B and Angle in Polygon
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides).

That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1v2v3 such that the angle (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value should be minimum possible.

If there are many optimal solutions, Mister B should be satisfied with any of them.

Input

First and only line contains two space-separated integers n and a (3 ≤ n ≤ 1051 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees.

Output

Print three space-separated integers: the vertices v1v2v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.

Examples
input
3 15
output
1 2 3
input
4 67
output
2 1 3
input
4 68
output
4 1 2
Note

In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.

Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".

In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".

题意:给一个正多边形和一个角度a,多边形顶点有标号1~n,找到s三个标号的夹角最接近角度a。

解决:算出多边形能分出的最小角,得出角度a需要num个角,固定1,2,第三个点为num+2。

细节:1.多边形边数大,计算最小角用double。

           2.考虑角小于最小角,角大于最大角。

#include <iostream>using namespace std;double n, a;int main(){    while(cin >>n >> a){        double s = (double) (180 * (n - 2)) / n;        double ss = (double) s / (n - 2);        int num = (int)a / ss;//        cout << num << endl;        if(!num) num++;        else if((a - ss * num) > (ss * (num+1) - a)) num++;//        cout << num << endl;        if(num + 2 > n) num = n - 2;        cout << 2 << " " << 1 << " " << num + 2 << endl;    }}


原创粉丝点击