天天看點

UVA - 11186-Circum Triangle

有個以坐标原點為圓心的圓,給出圓上的點的關于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);
	}
}