codeforces820B Mister B and Angle in Polygon
来源:互联网 发布:邮储银行网络培训学员 编辑:程序博客网 时间:2024/04/29 01:19
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 v1, v2, v3 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.
First and only line contains two space-separated integers n and a (3 ≤ n ≤ 105, 1 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees.
Print three space-separated integers: the vertices v1, v2, v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.
3 15
1 2 3
4 67
2 1 3
4 68
4 1 2
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".
题目的意思是给出一个正n凸多边形,让你选择3个顶点所成角度尽可能接近给出的角度k
思路:我们选一个顶点把他和与他不相邻的点连线一定会把一个角(n-2)等分,枚举选择的角度与k比就好了
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<string>#include<queue>#include<stack>#include<map>#include<set>using namespace std;#define LL long longconst int inf=0x3f3f3f3f;int main(){ int n,x; scanf("%d%d",&n,&x); double p=180.0/n; double ans=inf; int cnt=-1; for(int i=1; i<=n-2; i++) { if(fabs(ans-x)-fabs(p*i-x)>1e-9) ans=p*i,cnt=i; } printf("%d %d %d\n",n-cnt,1,n); return 0;}
- codeforces820B Mister B and Angle in Polygon
- CF820B-Mister B and Angle in Polygon
- B. Mister B and Angle in Polygon 421.div2
- Codeforces 820B Mister B and Angle in Polygon
- CF #421 B. Mister B and Angle in Polygon
- codeforces 820B Mister B and Angle in Polygon
- CodeForces 820B Mister B and Angle in Polygon
- Codeforces Round #421 B. Mister B and Angle in Polygon
- Codeforces#421 Mister B and Angle in Polygon
- CF820B:Mister B and Angle in Polygon(数学 & 几何)
- Codeforces Round #421 (Div. 2) B. Mister B and Angle in Polygon
- Codeforces Round #421 (Div. 2) | B. Mister B and Angle in Polygon
- #421 Div.2 B. Mister B and Angle in Polygon——几何数学
- Mister B and Book Reading
- Mister B and Book Reading
- CF820A-Mister B and Book Reading
- Codeforces820A Mister B and Book Reading
- A. Mister B and Book Reading
- Camera和Camera2的应用
- sublime Text 3配置
- Druid Spring Boot Starter数据库链接池新福利
- 百家争鸣:Android开源框架排行榜
- UnityShader之毛绒绒效果
- codeforces820B Mister B and Angle in Polygon
- Java深度拷贝对象
- 二叉树、树、森林之间的转化
- MySQL主从复制实现基于日志点的复制
- 一篇不错的面试文章
- Android常用开源项目(三十五)
- 计算机网络 —— URI和URL
- vivo和OPPO手机刷机
- Android自定义View,实现全屏滑动的DrawerLayout