Circum Triangle - UVa 11186 三角形面积

39 篇文章 0 订阅

Circum Triangle 
Input: 
Standard Input

Output: Standard Output

 

You will be given N distinct points on the boundary of a circle whose center is at the origin. As the points are on the same circle no three of them are collinear, so any three of them creates a valid triangle. Your job is to find the summation of areas of these nc3 triangles.

 

Input

Input file contains at most 16 sets of inputs. The description of each set is given below:

 

Each set starts with two integers N (0 ≤ N ≤ 500) and R(0<R ≤ 100). Here N is the number of points and R is the radius of the circle. You can assume that the center of the circle is always at the origin. This line is followed by N lines each of which contains a floating-point number theta (0.0<=theta<360.00) which actually denotes the angle in degree the designated point creates with respect to the origin with x-axis. So for example if theta is 30.00 degree then the Cartesian coordinate of the intended point is (and. Assume that pi=2cos-1(0).

 

Input is terminated by a set where the value of N and R is zero.  This set should not be processed.

 

Output
For each line of input produce one line of output. This line contains an integer number which is the total area (rounded to nearest integer) of all possible triangles formed by the given N points. The judge data will be such that small precision errors will not cause the output to be different. Consider at least double-precision floating numbers to do your calculations.

 

Sample Input                                  Output for Sample Input

5 10
10.00
100.00
300.00
310.00
320.00
3 20
10.00
100.00
300.00
0 0

286

320

 



题意:就是求n个点可以组成的三角形的面积之和。

思路:运用叉积求三角形面积。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
double r,x[510],y[510],p,ans,eps=1e-8;
double multiply(int a,int b)
{
    return x[a]*y[b]-y[a]*x[b];
}
double area(int a,int b,int c)
{
    return abs(multiply(a,b)+multiply(b,c)+multiply(c,a));
}
int main()
{
    int i,j,k;
    while(~scanf("%d%lf",&n,&r))
    {
        if(n==0 && r==0)
          break;
        ans=0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf",&p);
            p=p/180*M_PI;
            x[i]=r*cos(p);
            y[i]=r*sin(p);
        }
        for(i=1;i<=n;i++)
           for(j=i+1;j<=n;j++)
              for(k=j+1;k<=n;k++)
                 ans+=area(i,j,k);
        printf("%.0f\n",ans/2);
    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值