1799 Yeehaa!

Description

Background
George B. wants to be more than just a good American. He wants to make his daddy proud and become a western hero. You know, like John Wayne.
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).
Problem
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 with radius r that 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.

Input

The first line contains the number of scenarios. For each scenario follows a line containing a real number R and an integer n, with 1 <= R <= 100 and 2 <= n <= 100.

Output

The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print the value for r, rounded to three decimal places. Terminate the output for the scenario with a blank line.

Sample Input

4
4.0 6
4.0 17
3.14159 100
42 2

Sample Output

Scenario #1:
1.333

Scenario #2:
0.621

Scenario #3:
0.096

Scenario #4:
21.000

Source
TUD Programming Contest 2004, Darmstadt, Germany


任意两个小圆圆心之间的距离是2r,将这两个小圆的圆心以及大圆圆心相连构成一个等腰三角形,顶角的角度为 θ=360/n ,依据正弦定理,可以将两小圆圆心的距离表示为 2r=(Rr)sin(θ)/sin(90θ/2) ,求解方程即可。


#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

#define PI 3.14159258

int main()
{
    int sce;

    cin >> sce;
    for(int i=1;i<=sce;i++)
    {
        double R, r;
        int n;

        cin >> R >> n;
        r = (sin(PI / n)*R) / (1 + sin(PI / n));
        cout << "Scenario #" << i << ":" << endl;
        cout << fixed << setprecision(3) << r << endl << endl;
    }

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值