Hype (mathematics)

Links: https://ac.nowcoder.com/acm/contest/992/F
Source: Cattle-off network

Title Description

On a certain day, Qi earners get to the design drawings of a very beautiful ceiling pattern.
Frame pattern is a first n-gon, then the midpoint of its sides is n vertices of a regular n new modification. After repeated so many times, a pattern can be obtained the ceiling frame.
Do not ask how many times repeated, ask that repeats indefinitely. . .
Given n, seeking to generate a frame pattern sum of the lengths of all edges (the long sides of the first n-gon are each edge 100).

Enter a description:

Several test (no more than 100 groups), each line an integer n (2 <n <= 100), represents the number of sides of the regular polygon.

Output Description:

For each test, a result output line, rounded to two decimal places. (Please relatively simple calculation, in order to reduce the error)
Example 1

Entry

copy
3
4
50

Export

copy
600.00
1365.69
2533863.09

Analysis: This is a very simple mathematical derivation, it is easy to know the n-gon degree interior angle to each PI * (n - 2) / n, with this, the law of cosines can be obtained by repeating inside it a first n-gon side length 

Wherein α is the n-gon interior angle, x is a side, then it can be seen, each side consisting of a geometric sequence length, the above equation is in addition to the common ratio x, then you can use the geometric series summation and get the final formula, (middle using a limit)

Finally, as long as the side length and the number of edges into the ride on the line, the final result is 

code show as below:

#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int n;

int main(){
    while(scanf("%d", &n) == 1){
        double a = cos(PI * (n - 2) / n);
        double ans = 100.0 * n * (2 + sqrt(2-2*a)) / (1 + a);
        printf("%.2f\n", ans);
    }
    return 0;
}

  

 

Guess you like

Origin www.cnblogs.com/dwtfukgv/p/11223605.html