题意:
给定一个圆的半径、已经小圆的个数。让你求出小圆的半径,使半径尽量大。
思路:
一开始以为是大圆的周长除以小圆的个数,然后得到小圆的直径。后来才发现是自己逗了。
正确的姿势是根据每个小圆所占的弧长计算。
二分小圆的半径,求出每个小圆对应的弧长,看是否符合个数条件。
AC代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
double R, len;
int n;
bool OK(double mid)
{
double y = R-mid;
double tmp = asin(mid/y);
int tn = floor(PI/tmp);
return tn >= n? true:false;
}
int main()
{
int T, cas = 0;
cin>>T;
while(T--)
{
cin>>R>>n;
double l = 0, r = R;
//
while(r - l > 1e-7)
{
double mid = (r+l)/2;
if(OK(mid))
l = mid;
else
r = mid;
}
printf("Case %d: %.6f\n", ++cas, l);
}
return 0;
}