给一个圆,原点(0.0),半径r,圆上n个点,任意三个点可以构成一个三角形,
求所有三角形的面积和。
三层for, 数据500可行。
//UVA-11186
//for *3 ,叉积算三角形面积
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
struct node{
double x,y;
}dot[505];
double cal(node a,node b,node c){
node t1 = {a.x - b.x,a.y - b.y};
node t2 = {a.x - c.x,a.y - c.y};
double ans = t1.x*t2.y - t1.y*t2.x;
ans/=2;
if(ans<0)ans=-ans;
return ans;
}
int main()
{
int n;
double r;
while(scanf("%d %lf",&n,&r)>0){
if(n==0&&r==0){
return 0;
}
double angle;
for(int i=0;i<n;i++){
scanf("%lf",&angle);
dot[i].x = r*cos(angle/180*pi);
dot[i].y = r*sin(angle/180*pi);
}
double ans = 0;
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n-1;j++){
for(int k=j+1;k<n;k++){
ans+=cal(dot[i],dot[j],dot[k]);
}
}
}
printf("%.0lf\n",ans);
}
return 0;
}