大圆小圆问题

NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles:

在这里插入图片描述
It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar picture himself.

He managed to calculate the number of outer circles n and the radius of the inner circle r. NN thinks that, using this information, you can exactly determine the radius of the outer circles R so that the inner circle touches all of the outer ones externally and each pair of neighboring outer circles also touches each other. While NN tried very hard to guess the required radius, he didn’t manage to do that.

Help NN find the required radius for building the required picture.

Input
The first and the only line of the input file contains two numbers n and r (3≤n≤100, 1≤r≤100) — the number of the outer circles and the radius of the inner circle respectively.

Output
Output a single number R — the radius of the outer circle required for building the required picture.

Your answer will be accepted if its relative or absolute error does not exceed 10−6.

Formally, if your answer is a and the jury’s answer is b. Your answer is accepted if and only when |a−b|max(1,|b|)≤10−6.

Examples
Input
3 1
Output
6.4641016
Input
6 1
Output
1.0000000
Input
100 100
Output
3.2429391
思路:这道题只要发现边和角的关系就行啦!!
一圈可由n个下图那样的等腰三角形组成,再利用R/(r+R)=sinα,α=(2pi)/(2n)。
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
const double pi=3.1415926535898;
int main()
{
    int n,r;
    cin>>n>>r;
    cout<<fixed<<setprecision(7)<<(r*sin(pi/n)*1.0)/(1-sin(pi/n))<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
小圆覆盖问题是一个经典的几何优化问题,其求解模型可以通过以下几种方法来实现: 1. Welzl算法:Welzl算法是一种递归的随机增量算法,用于寻找最小圆覆盖。该算法的基本思想是通过随机选择点,逐步构建包含这些点的最小圆。具体步骤包括:如果点集为空,则返回空;如果只有一个点,则返回以该点为心、半径为0的;如果有两个点,则返回以这两个点为直径的;对于多于两个点的情况,随机选择一个点,递归构建包含其余点的最小圆,并检查是否需要更新最小圆。该算法的时间复杂度为O(n)。 2. Graham扫描算法:Graham扫描算法是一种基于极角排序的凸包算法,也可以用于解决最小圆覆盖问题。该算法首先选取一个点作为起始点,并按照与起始点的极角大小进行排序。然后维护一个栈,依次将点入栈,并检查是否需要进行凸包的调整。最后,使用Welzl算法对凸包上的点进行最小圆覆盖的求解。该算法的时间复杂度为O(nlogn)。 3. 随机增量算法:随机增量算法是一种启发式算法,通过随机增加点来逼近最小圆覆盖。该算法的基本步骤包括:选取初始,并将点集分为内点和外点;在外点中随机选择一个点,将其添加到内,更新最小圆;重复上述步骤,直到所有点都被添加到内。该算法的时间复杂度与点的数量有关。 以上是常见的几种模型用于解决最小圆覆盖问题。具体选择哪种模型取决于问题规模、时间限制和精度要求等因素。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值