D.Thinking-Bear magic(2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛)

链接:https://www.nowcoder.com/acm/contest/163/D
来源:牛客网
 

Thinking-Bear magic

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

In order to become a magical girl, Thinking-Bear are learning magic circle.
He first drew a regular polygon of N sides, and the length of each side is a.
He want to get a regular polygon of N sides, and the polygon area is no more than L.
He doesn't want to draw a new regular polygon as it takes too much effort.
So he think a good idea, connect the midpoint of each edge and get a new regular polygon of N sides.
How many operations does it need to get the polygon he want?

输入描述:

The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains three space-separated integers N, a and L (3 ≤ N ≤ 10, 1 ≤ a ≤ 100, 1 ≤ L ≤ 1000).

输出描述:

For each test case, output a single integer.

示例1

输入

复制

1
4 2 3

输出

复制

1

思路:没什么好说的,纯数学题,画画图就明白了。

注意c++求三角函数sin、cos、tan里是弧度,不是角度。

       角度/180=弧度/π

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define pi 3.1415926535897932384626
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double n,a,l;
        int sum=0;
        cin>>n>>a>>l;
        double r=a/(2.0*sin(pi/n));  //外接圆半径
        double s=0.5*r*(r*sin(2.0*pi/n))*n;  //n边形面积  1/2*底*高*n
        while(s>l)
        {
            a=a*cos(pi/n);
            r=a/(2.0*sin(pi/n));
            s=0.5*r*(r*sin(2.0*pi/n))*n;
            sum++;
        }
        cout<<sum<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sunny_hun/article/details/81434976