Tuesday, March 9, 2010

UVa 10432

Finding the area of a polygon in a circle is fairly trivial if you remember basic trigonometry or you can make use of Wikipedia (like I did). The solution here uses the fact that a polygon is made up of many triangles and the area for a triangle whose SideAngleSide are known can be obtained using area = 1/2 * side * side * sin(angle). Initially I had gone for Law of Cosines and the Heron's formula but I could not get an AC so here is the code...

#include<iostream>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
double r,n;
while(scanf("%lf%lf",&r,&n)!=EOF) {
double res = n*.5*r*r*sin((2*M_PI/n));

printf("%.3lf\n",res);
}
return 0;

}

No comments:

Post a Comment