有个以坐标原点为圆心的圆,给出圆上的点的关于x轴的夹角,以及圆的半径,求圆上点所能构成的三角形的面积和
我的做法:
先算出每个点的坐标,枚举所有三个点的组合,叉积求面积
我的代码:
#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
struct dot
{
double x,y;
dot(){}
dot(double a,double b){x=a,y=b;}
friend dot operator -(dot a,dot b){return dot(a.x-b.x,a.y-b.y);}
friend double operator /(dot a,dot b){return a.x*b.x+a.y*b.y;}
friend double operator *(dot a,dot b){return a.x*b.y-a.y*b.x;}
};
double dis(dot a,dot b)
{
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double cang(dot a,dot b)
{
return acos(a/b/dis(a,dot(0,0))/dis(b,dot(0,0)));
}
double cg1(double a)
{
return a/pi*180;
}
double cg2(double a)
{
return a/180*pi;
}
int main()
{
int n,i,j,k;
double r,t,ans;
dot a[510];
while(cin>>n>>r)
{
if(n+r==0)
break;
for(i=0;i<n;i++)
{
cin>>t;
t=cg2(t);
a[i]=dot(r*cos(t),r*sin(t));
}
ans=0;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
for(k=j+1;k<n;k++)
ans+=fabs((a[j]-a[i])*(a[k]-a[i])/2);
printf("%.0lf\n",ans);
}
}