UVA - 11186 Circum Triangle (几何)

Posted SomnusMistletoe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA - 11186 Circum Triangle (几何)相关的知识,希望对你有一定的参考价值。

题意:有N个点,分布于一个圆心在原点的圆的边缘上,问所形成的所有三角形面积之和。

分析:

1、sin的内部实现是泰勒展开式,复杂度较高,所以需预处理。

2、求出每两点的距离以及该边所在弧所对应的圆周角。一条弧所对圆周角等于它所对圆心角的一半。

3、S = 1/2*absinC求三角形面积即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 500 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int N;
double R;
double Sin[MAXN][MAXN];
double dist[MAXN][MAXN];
struct Node{
    double x, y, rad;
    void read(){
        scanf("%lf", &rad);
        rad = rad / 180.0 * pi;
        x = R * cos(rad);
        y = R * sin(rad);
    }
}num[MAXN];
double getDist(int i, int j){
    return sqrt((num[i].x - num[j].x) * (num[i].x - num[j].x) + (num[i].y - num[j].y) * (num[i].y - num[j].y));
}
int main(){
    while(scanf("%d%lf", &N, &R) == 2){
        if(N == 0 && R == 0) return 0;
        memset(Sin, 0, sizeof Sin);
        memset(dist, 0, sizeof dist);
        for(int i = 0; i < N; ++i){
            num[i].read();
        }
        for(int i = 0; i < N; ++i){
            for(int j = i + 1; j < N; ++j){
                Sin[i][j] = sin(fabs(num[j].rad - num[i].rad) / 2.0);
                dist[i][j] = dist[j][i] = getDist(i, j);
            }
        }
        double sum = 0.0;
        for(int i = 0; i < N; ++i){
            for(int j = i + 1; j < N; ++j){
                for(int k = j + 1; k < N; ++k){
                    sum += dist[i][j] * dist[i][k] * Sin[j][k] / 2;
                }
            }
        }
        double ans = round(sum);
        printf("%.0lf\n", ans);
    }
    return 0;
}

  

以上是关于UVA - 11186 Circum Triangle (几何)的主要内容,如果未能解决你的问题,请参考以下文章

Constants and the C Preprocessor

LintCode 数字三角形

Word List 1 part 1

Divisors

in packet sniffer

JZ33 丑数