zoukankan      html  css  js  c++  java
  • D Thanking-Bear magic

    题目描述

    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


    思路:弱弱的推了一半天,在大佬的指点之下终于推出了公式;题意是讲若当前多边形的面积大于L就将每条边的中点依次连接构成一个新的多边形 求多少次这种操作之后面积S不大于L;首先已知多边形边长为a,外接圆半径R = a/(2*sin(pi/n)); 面积S = 0.5*n*R^2*sin((2*pi)/n);
      然后以此类推求出内接正多边形的边长与内接正多变形的外接圆半径r;内接正多变的边长x = a*cos(pi/n);emmmmm就以此类推下去了吧下面附上代码
     1 #include<iostream>
     2 #include<cmath>
     3 #define pi  3.141592653589793238462643383
     4 using namespace std;
     5 
     6 int T,n;
     7 double a,L;
     8 int main()
     9 {
    10     ios::sync_with_stdio(false);
    11     cin>>T;
    12     while(T--){
    13         cin>>n>>a>>L;
    14         double R = a/(2.0*sin(pi/n));
    15         double s = 0.5*n*R*R*sin((2*pi)/n);
    16         double r;int ans = 0;
    17         while(s>L){
    18             ans++;
    19             a = a*cos(pi/n);
    20             r = a/(2.0*sin(pi/n));
    21             s = 0.5*n*r*r*sin((2*pi)/n);
    22         }
    23         cout<<ans<<endl;
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    如何使用gitbash 把你的代码托管到github
    发送邮件错误常见错误码
    使用snipworks/php-smtp发送邮件
    微信支付demo
    Linux——ps命令
    数组对象互转
    变量名下划线和驼峰互转
    对象数组转换
    curl请求
    百度地图接口的使用
  • 原文地址:https://www.cnblogs.com/wangrunhu/p/9426513.html
Copyright © 2011-2022 走看看