B. Mister B and Angle in Polygon 421.div2
2017-06-28 07:23
567 查看
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 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.
Input
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.
Output
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.
Examples
input
output
input
output
input
output
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".
题意:就是给你一个正则凸n变形,确定一定由三个不同定点构成的角,是的这个角-a的绝对值最小。
思路:利用的是同一个圆上等弧对应的圆周角相等,所以固定一个定点,枚举一边就ok了。
上代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
double n,a;
while(scanf("%lf%lf",&n,&a) != EOF)
{
int nn = n;
int i,j;
double tmp;
int x,y;
double out=360.0;
double cc = (n-2)*180.0/n;
for(i=2; i<=2; i++)
{
for(j=i+1; j<=n; j++)
{
tmp = ((j-2)*180.0 - cc*(j-2)) / 2.0;
if(fabs(tmp-a) < out){x=i,y=j; out=fabs(tmp-a);}
if(out<= 0.00001) break;
}
}
printf("%d 1 %d\n",x,y);
}
return 0;
}
水波。
→ Virtual participation
Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems
in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never
use someone else's code, read the tutorials or communicate with other person during a virtual contest.
→ Practice
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
→ Submit?
→ Last submissions
→ Problem tags
No tags yet
No tag edit access
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 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.
Input
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.
Output
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.
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".
题意:就是给你一个正则凸n变形,确定一定由三个不同定点构成的角,是的这个角-a的绝对值最小。
思路:利用的是同一个圆上等弧对应的圆周角相等,所以固定一个定点,枚举一边就ok了。
上代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
double n,a;
while(scanf("%lf%lf",&n,&a) != EOF)
{
int nn = n;
int i,j;
double tmp;
int x,y;
double out=360.0;
double cc = (n-2)*180.0/n;
for(i=2; i<=2; i++)
{
for(j=i+1; j<=n; j++)
{
tmp = ((j-2)*180.0 - cc*(j-2)) / 2.0;
if(fabs(tmp-a) < out){x=i,y=j; out=fabs(tmp-a);}
if(out<= 0.00001) break;
}
}
printf("%d 1 %d\n",x,y);
}
return 0;
}
水波。
Codeforces Round #421 (Div. 2) |
---|
Finished |
Practice |
→ Virtual participation
Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems
in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never
use someone else's code, read the tutorials or communicate with other person during a virtual contest.
→ Practice
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
→ Submit?
Language: | GNU GCC 5.1.0GNU GCC C11 5.1.0 GNU G++ 5.1.0GNU G++11 5.1.0 GNU G++14 6.2.0 Microsoft Visual C++ 2010 C# Mono 3.12.1.0MS C# .NET 4.0.30319 D DMD32 v2.071.2 Go 1.7.3Haskell GHC 7.8.3 Java 1.8.0_112 Kotlin 1.0.5-2OCaml 4.02.1 Delphi 7 Free Pascal 2.6.4Perl 5.20.1 PHP 7.0.12 Python 2.7.12Python 3.5.2 PyPy 2.7.10 (2.6.1) PyPy 3.2.5 (2.4.0) Ruby 2.0.0p645Rust 1.12.1 Scala 2.11.8 JavaScript V8 4.8.0 |
Choose file: | |
Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it a7f1 will pass system tests. |
→ Last submissions
Submission | Time | Verdict |
---|---|---|
28104928 | Jun/28/2017 01:59 | Accepted |
28104865 | Jun/28/2017 01:49 | Time limit exceeded on test 6 |
28104856 | Jun/28/2017 01:47 | Wrong answer on test 1 |
28098288 | Jun/27/2017 19:34 | Time limit exceeded on pretest 6 |
→ Problem tags
No tags yet
No tag edit access
相关文章推荐
- #421 Div.2 B. Mister B and Angle in Polygon——几何数学
- CF #421 B. Mister B and Angle in Polygon
- Codeforces Round #421 (Div. 2) B. Mister B and Angle in Polygon
- Codeforces#421 Mister B and Angle in Polygon
- 【Codeforces Round #421 (Div. 2) B】Mister B and Angle in Polygon
- Codeforces Round #421 B. Mister B and Angle in Polygon
- CF820B-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
- codeforces820B Mister B and Angle in Polygon
- [数论] Codeforces819D. Mister B and Astronomers
- MeteoInfoLab脚本示例:inpolygon
- Codeforces Round #421 (Div. 2) A. Mister B and Book Reading
- Euler Angle in a picture
- Generic Polygon Module in MAME 0.120u1
- matlab inpolygon 判断点在多边形内
- Codeforces Round #421 (Div. 2) C. Mister B and Boring Game
- Codeforces 819 C. Mister B and Beacons on Field 容斥 数学
- 【Codeforces Round #421 (Div. 2) A】Mister B and Book Reading
- Mister B and Book Reading