Lightoj1072——Calm Down(计算几何)

George B. wants to be more than just a good American. He wants to make his daddy proud and become a hero. You know, like Shakib Khan.

But sneaky as he is, he wants a special revolver that will allow him to shoot more often than just the usual six times. This way he can fool and kill the enemy easily (at least that's what he thinks, and that's the best he can think). George has kidnapped . . . uh, I mean . . . "invited" you and will only let you go if you help him with the math. The piece of the revolver that contains the bullets looks like this (examples for 6 and 17 bullets):

There is a large circle with radius R and n little circles each having radius r, are placed inside on the border of the large circle. George wants his bullets to be as large as possible, so there should be no space between the circles. George will decide how large the whole revolver will be and how many bullets it shall contain. Your job is, given R and n, to compute r. You have decided to help, because you know that an idiot can't make a revolver even if you help him with the math.

Input

Input starts with an integer T (≤ 125), denoting the number of test cases.

Each case contains a real number R (0 < R < 1000 and contains up to at most two places after the decimal point) and an integer n (2 ≤ n ≤ 100).

Output

For each test case, print the case number and r in a single line. Errors less than 10-6 will be ignored.

Sample Input

Output for Sample Input

4

4.0 6

4.0 17

3.14 100

42 2

Case 1: 1.3333333333

Case 2: 0.6209067545

Case 3: 0.0956260953

Case 4: 21



求小圆的半径。连接大圆圆心与一个小圆的圆心,再连接大圆圆新和这个小圆与另一个小圆的交点,就可以得到一个直角三角形。我在做这题的时候画错了图结果答案老错。。。


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<cmath>
#define MAXN 10000
using namespace std;
int main()
{
    int t,cnt=1,i,j;
    double n,R,r;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf",&R,&n);
        r=(R*sin(M_PI/n))/(1+sin(M_PI/n));
        if(fabs(r-int(r))<=0.0000001)
            printf("Case %d: %d\n",cnt++,(int)r);
        else
            printf("Case %d: %.10lf\n",cnt++,r);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值