Thinking-Bear magic (计算几何)

 ---- 点我 ---- 题目大意:

给你一个正n边形及边长 a和一个正整数L,

求正多边形的面积s,若s大于L,则连接相邻两边的中点,形成新的正多边形,重复这个操作直至s小于L:如图:

正多边形的面积 : S = n*a^*a / (4tan(α/2);

n 为边数, a为当前边长,α为圆心角;

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long lint;
const double PI = acos(-1.0);
const int INF = 1000000000;
const int maxn = 100005;
double a, n, S, sn, c;

void st(double a) //求面积
{
    sn = n * a * a / 4 / tan(c/2);
}

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int cnt = 0;
        cin >> n >> a >> S;
        c = 360 / n / 180 * PI;    // 圆心角的弧度值
        double b = 180 * (n-2) * PI / n / 180;     // 正多边形的每个角的弧度
        sn = n * a * a / 4 / tan(c/2);   //初始面积
        // cout << sn << endl;
        while(sn >= S)
        {
            a *= sin(b/2);    // 操作后的边长与原边长的关系;
            st(a);  // 更新面积
            cnt++;  // 操作次数加加
        }

        cout << cnt << endl;
    }


    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mrh-acmer/p/9426378.html