题目
{% fold 点击显/隐题目 %}
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 is the vertex of the angle, and and lie on its sides) is as close as possible to . In other words, the value $\left| \angle v_1 v_2 v_3 - a \right| $ should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them.
题解
题意
正n
边形选3个顶点,使拼合成的角使所有角中最接近a
的
需要的数学知识:
正n边形内角和:
对于如图所示的角,其角度为
同样,可以证明(数学归纳法)得到 正好可以覆盖所有的可以取到的角度
所以,只要枚举 即可
代码
{% fold 点击显/隐代码 %}```cpp Mister B and Angle in Polygon https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
//
#define debug
#include
//
#include
#include
#include
#include
using namespace std;
const double eps = 1e-5;
int main() {
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif
cin.tie(0);
cin.sync_with_stdio(false);
double n, a;
while (cin >> n >> a) {
double tot = 180 * (n - 2);
double t = tot / n;
double Min = 9e9;
double pos = 0;
for (int i = 1; i <= n - 2; i++) {
double temp = (180 * i - t * i) / 2;
//cout << "2 1 " << i + 2 << " " << temp << " " << fabs(temp - a)
//<< " "<<Min<<endl;
if (fabs(temp - a) < Min) {
Min = fabs(temp - a);
pos = i;
}
}
cout << "2 1 " << pos + 2 << endl;
}
#ifdef debug
printf("Time:%.3fs.\n", double(clock() - START) / CLOCKS_PER_SEC);
#endif
return 0;
}
{% endfold %}