UVA 1524 - Hot or Cold?(数学)
UVA 1524 - Hot or Cold?
题目链接
题意:给一个一元n次方程,带入x表示时间,f(x)表示温度,如今要求[s, e]的平均温度
思路:平均温度就是 总温度/ (e - s),画出曲线,能够发现温度总和为[s,e]上区间与x轴围成的面积,那么利用f(x)的原函数就能求面积了
代码:
#include
#include
#include 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;
} 转载于:https://www.cnblogs.com/zfyouxi/p/4092451.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
