1. 程式人生 > >Thinking-Bear magic (計算幾何)

Thinking-Bear magic (計算幾何)

return name code 數加 重復 ack tps href tac

---- 點我 ---- 題目大意:

給你一個正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; }

Thinking-Bear magic (計算幾何)