链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2127
题意: 圆心在原点,半径为 R 的圆,其边上有 N 个点, 任意三点组成一个三角形, 求三角形面积和~
思路: 利用叉积求面积~暴力求三角形~
1 #include <cstdio> 2 #include <cmath> 3 #include <iostream> 4 #include <algorithm> 5 #include <cstring> 6 using namespace std; 7 const double Pi=acos(-1); 8 const double eps=1e-8; 9 struct Point 10 { 11 double x, y; 12 Point(){} 13 Point(double _x, double _y){ 14 x=_x, y=_y; 15 } 16 inline Point operator - (const Point A)const { 17 return Point(x-A.x, y-A.y); 18 } 19 inline double operator ^ (const Point A)const{ 20 return x*A.y-y*A.x; 21 } 22 inline double operator * (const Point A)const{ 23 return x*A.x+y*A.y; 24 } 25 }p[505]; 26 double Area( Point A, Point B, Point C ) 27 { 28 return fabs(((A-B)^(A-C))/2.0); 29 } 30 int N; 31 double r, a; 32 int main( ) 33 { 34 while( scanf("%d%lf", &N, &r)!= EOF ){ 35 if(N==0 && r==0)break; 36 for(int i=0; i<N; ++ i ){ 37 scanf("%lf", &a); 38 p[i]=Point( r*cos(a/180.0*Pi), r*sin(a/180.0*Pi) ); 39 } 40 double ans=0; 41 for( int i=0; i<N; ++ i ){ 42 for( int j=i+1;j<=N; ++ j ){ 43 for( int k=j+1; k<N; ++ k ){ 44 ans+=Area( p[i], p[j], p[k] ); 45 } 46 } 47 } 48 printf("%.0lf ", ans); 49 } 50 51 return 0; 52 }