`
阿尔萨斯
  • 浏览: 4185124 次
社区版块
存档分类
最新评论

uva 1524 - Hot or Cold?(积分)

 
阅读更多

题目链接:uva 1524 - Hot or Cold?

题目大意:给定一个气温变化的函数,求平均值。

解题思路:对给定函数与坐标轴形成的面积即为总值,所以对函数做积分即可。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using  namespace std;
const int maxn = 1005;

int N;
double s, e, a[maxn];

double f (double x) {
    double ret = 0;
    for (int i = 0; i <= N; i++)
        ret += a[i] * pow(x, i+1);
    return ret;
}

int main () {
    while (scanf("%d", &N) == 1 && N) {
        for (int i = N; i >= 0; i--) {
            scanf("%lf", &a[i]);
            a[i] /= (i+1);
        }
        scanf("%lf%lf", &s, &e);
        printf("%.3lf\n", (f(e) - f(s)) / (e - s));
    }
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics