P. Area of a Star
time limit per test0.5 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard outputIt 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 r n 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.
Examples input 7 10 output 108.395919545675
这题简直坑爹,要求求中间星星的面积,一开始我用圆形面积减去n个空白处的扇形面积发现精度简直坑爹,直接过不了样例: (过不了样例的程序
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[5],key,pp;
int n;
double pi,r,rr,s,L,ang;
double dis(Point p1,Point p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
Point inter(Point p1,Point p2,Point p3,Point p4){
double a1=p1.y-p2.y;
double b1=p2.x-p1.x;
double c1=p1.x*p2.y-p1.y*p2.x;
double a2=p3.y-p4.y;
double b2=p4.x-p3.x;
double c2=p3.x*p4.y-p3.y*p4.x;
double x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
double y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
return Point(x,y);
}
int main(){
freopen("tx.in","r",stdin);
scanf("%d%lf",&n,&r);
pi=acos(-1);
ang=(2*acos(-1))/n;
p[0].x=r;p[0].y=0.0;
p[1].x=cos(ang*1)*r;
p[1].y=sin(ang*1)*r;
p[2].x=cos(ang*(n/2))*r;
p[2].y=sin(ang*(n/2))*r;
p[3].x=cos(ang*(n/2+2))*r;
p[3].y=sin(ang*(n/2+2))*r;
pp=inter(p[0],p[2],p[1],p[3]);
L=ang*r;
rr=r-sqrt(pp.x*pp.x+pp.y*pp.y);
s=pi*r*r-(double)(n*rr*L/2.0);
printf("%lf",s);
}
之后我们换种想法,我们可以考虑三角形ABO,我们可以轻松获知角CDE为2π/n(因为每个都相等,加起来为圆周), 由圆上角=圆心角的一半可得,∠BAE=π/n,∠BAO=π/2n,且∠BOA为(1/2n)*2π即π/n,已知AO=r,由正弦定理: a/sinA=b/sinB=c/sinC可知BO、AB长度,最终用面积公式S=1/2*a*b*SinC可得答案。 AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int n;
double r;
int main(){
scanf("%d%lf",&n,&r);
double A,B,C,a,b,c,s=0;
a=r;B=acos(-1)/(2*n);C=acos(-1)/n;
A=acos(-1)-B-C;
b=a*sin(B)/sin(A);
s=0.5*a*b*sin(C);
s=2*n*s;
printf("%.12f",s);
}



