Circle HDU - 6550 (数学)
生活随笔
收集整理的這篇文章主要介紹了
Circle HDU - 6550 (数学)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在半徑為 1 的圓上有 n 個點,它們也是圓的 n 等分點,將每個相鄰的 n 等分點相連,組成了一個正 n邊形,現(xiàn)在你可以在圓上再增加一個點,使得新的 n + 1 邊形的面積最大,請輸出最大面積。
Input
輸入有多組(不超過 100 組)。
每組數(shù)據(jù)一行一個整數(shù) n 代表點的數(shù)量。
3 ≤ n ≤ 100
Output
每組數(shù)據(jù)輸出一行一個數(shù)表示加上一個點后的最大面積,結果保留6位小數(shù)。
Sample Input
3
Sample Output
1.732051
思路:
例如n=4的時候,可以證明出第n+1個點選在紅點的位置可以使多邊形的面積最大。
這個多邊形的面積就用余弦定理和三角形內角的關系來求即可。
細節(jié)見代碼:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> #define ALL(x) (x).begin(), (x).end() #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long long ,long long> #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define MS0(X) memset((X), 0, sizeof((X))) #define MSC0(X) memset((X), '\0', sizeof((X))) #define pb push_back #define mp make_pair #define fi first #define se second #define eps 1e-6 #define gg(x) getInt(&x) #define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl using namespace std; typedef long long ll; ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;} inline void getInt(int* p); const int maxn = 1000010; const int inf = 0x3f3f3f3f; /*** TEMPLATE CODE * * STARTS HERE ***/typedef long double ld; ld n; const ld pi = acos(-1);int main() {//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);while(cin >> n){ld a=360.0000/n;a=a/180*pi;ld S=0.5*sin(a);S*=(n-1);a/=2.000;S+=sin(a);cout<<fixed<<setprecision(6)<<S<<endl;}return 0; }inline void getInt(int* p) {char ch;do {ch = getchar();} while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 + ch - '0';}} }轉載于:https://www.cnblogs.com/qieqiemin/p/11308570.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結
以上是生活随笔為你收集整理的Circle HDU - 6550 (数学)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LAMP 系统性能调优,第 3 部分:
- 下一篇: 基本排序算法及分析(二):冒泡排序