题解 UVA11186 【正多边形 Circum Triangle】

2019-03-05 19:26:26


计算几何的一道基础题吧

我们假设圆心在(0,0),半径为r

那么 圆心角为p 的点在 $(cos(p) * r,sin(p)*r)$

然后我们可以暴力枚举三个点,用叉积算三角形面积

code

#include<bits/stdc++.h>
using namespace std;

#define db double
#define MAXN 10005
#define esp 1e-9
#define xl dian 
const db pi = acos(-1);

struct dian
{
    db x,y;
 } a[MAXN];
int n,m; 
db r;

xl operator -(xl a,xl b) {
    return (xl){a.x - b.x,a.y - b.y};
}

inline db chaji(xl a,xl b)
{
    return a.x * b.y - a.y*b.x;
}

inline db mianji(dian a,dian b,dian c)
{
    return fabs(chaji(b-a,c-a));
}

int main()
{
    while(1)
    { 
        cin >> n >> r;
        if(n == 0 && abs(r) <= esp) {
            return 0;
        }
        for(int i = 1; i <= n; i ++)
        {
            db p;
            scanf("%lf",&p);
            p = p/180*pi;
            a[i].x = cos(p)*r;
            a[i].y = sin(p)*r;

        } 
        db ans = 0;
        for(int i = 1; i <= n; i ++)
            for(int j = i+1; j <= n; j ++)
                for(int k = j+1; k <= n; k ++)
                ans += mianji(a[i],a[j],a[k]);
        printf("%.0lf\n",ans/2);
    } 
    return 0;
 }