Description
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star.
A "star" figure having n ≥ 5 corners where n is a prime number is constructed the following way. On the circle of radius rn points are selected so that the distances between the adjacent ones are equal. Then every point is connected by a segment with two maximally distant points. All areas bounded by the segments parts are the figure parts.
Input
The only line of the input contains two integers n (5 ≤ n < 109, n is prime) and r (1 ≤ r ≤ 109) — the number of the star corners and the radius of the circumcircle correspondingly.
Output
Output one number — the star area. The relative error of your answer should not be greater than 10 - 7.
Sample Input
7 10
108.395919545675
#include<cstdio>
#include<cmath>
#define PI acos(-1.0)
int main()
{
double n,r,x,y,z,len,s;
scanf("%lf%lf",&n,&r);
x=PI/(2*n);
y=PI/n;
z=PI-x-y;
len=r*sin(x)/sin(z);
s=len*r*sin(y)*n;
printf("%.8lf\n",s);
return 0;
}
我自己第一次想到的(复杂):边接所有顶点,及其到圆心,得到n个三角形,三角形内还有小三角,求出三角形的面积减去小三角的面积乘以n即可,但是就是不对。。。。
#include<cstdio>
#include<cmath>
#define PI acos(-1.0)
int main()
{
double r,n,y,x,l,d,s,ans;
scanf("%lf%lf",&n,&r);
y=PI/n;
x=PI/2+PI/(2*n);
l=2*r*sin(y);
d=l/(2*tan(x/2));
s=l*r*cos(y)/2-d*l/2;
ans=n*s;
printf("%.8lf\n",ans);
return 0;
}