UVA 1524 - Hot or Cold?
题意:给一个一元n次方程,带入x表示时间,f(x)表示温度,如今要求[s, e]的平均温度
思路:平均温度就是 总温度/ (e - s),画出曲线,能够发现温度总和为[s,e]上区间与x轴围成的面积,那么利用f(x)的原函数就能求面积了
代码:
#include <cstdio>
#include <cstring>
#include <cmath> const int N = 105; int n;
double a[N], s, e; double F(double x) {
double ans = 0;
for (int i = 0; i <= n; i++)
ans += a[i] * pow(x, i + 1);
return ans;
} int main() {
int cas = 0;
while (~scanf("%d", &n) && n) {
for (int i = n; i >= 0; i--) {
scanf("%lf", &a[i]);
a[i] = a[i] / (i + 1);
}
scanf("%lf%lf", &s, &e);
printf("%.3lf\n", (F(e) - F(s)) / (e - s));
}
return 0;
}