题目
A circumscribed circle of a polygon is the circle that passes through all the vertices of that polygon.
Let’s assume we have a regular polygon, we want to find the area of the circumscribed circle around this polygon. Given the number of vertices and the side length of the polygon, can you find the circle’s area?
Input
The only line contains 2 integers , V(3≤V≤359) the number of vertices of the polygon and S(1≤S≤1e9)
Output
Find the area of the resulting circumscribed circle.Your answer will be considered correct if its absolute or relative error does not exceed 1e−6.
Namely: let’s assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if |a−b|/max(1,b)≤1e-6.
Example
Input
8 2
Output
21.452136491
Note
The octagon in the picture illustrates the first example.
题意
给出一个多边形的边数和边长,求这个多边形的外接圆面积。
解析
设正N边形的外接圆圆心O,O也是正N边形的中心,圆心与正N边形顶点A的连线OA(也就是圆半径)是正N边形那个顶角的角平分线,而正N边形顶角度数为180-360/N,假设正N边形的边长为L,与A相邻的另一个顶点为B,则等腰三角形OAB的两个底角θ= 90-180/N 半径OA=L/2÷cosθ 。
正确代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
const double pi = acos(-1.0);//acos函数的作用是返回输入值所对应的弧度
int main()
{
double n,l;
scanf("%lf %lf",&n,&l);
double x=cos(pi/2-pi/n);
double s=pi*(l*l)/(4*x*x);
printf("%f\n",s);
return 0;
}