I - The Queen’s Super-circular Patio

题意:
现有一个半径为1的圆,然后给出一层要求填充完的圆的个数和层数,求最外层的填充圆的半径和将其围起来的栏杆周长(周长就等于前面半径对应的圆的周长加上n × 直径)

题解:
https://www.cnblogs.com/starve/p/11164586.html

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

#define lowbit(x) x & (-x)
#define lson left,mid,root << 1
#define rson mid+1,right,root << 1 | 1

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=1e5+100;


int main()
{
   int t;
   int p, n, k;
   scanf("%d",&t);
   while(t --)
      {
        scanf("%d %d %d",&p, &n, &k);
        double r0 = 1.0 * pi / n;
        double r1 = 1;
        double r2 = sin(r0) / (1 - sin(r0));
        double a = 1 / (tan(r0) * tan(r0));
        double b = -2 * ((r1 + r2) / tan(r0) + r2);
        double c = r1 * r1 + 2 * r1 * r2;
        double r3 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
        double r;
        for(int i = 3; i <= k; i ++)
          {
            r = r3 * r3 /r2;
            r2 = r3;
            r3 = r;
          }
        if(k == 1)
            r = r2;
        if(k == 2)
            r = r3;
        printf("%d %.3lf %.3lf\n",p, r, 2 * pi * r + n * 2 * r);
      }

   return 0;
}

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注