题目链接: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;
}
分享到:
相关推荐
判断输入字符串是否为镜像或回文串。 来源于UVaOJ - 401. 水题。
开源项目-codingsince1985-UVa#uva-online-judge-solutions-in-golang.zip,两年来每天都在解决一个uva在线裁判问题,算起来…
uva705 Slash Maze 的代码,在UVaOJ上通过
PDF试题
UVA 10474
Algorithm-UVA-Solutions-in-Python.zip,python 3中各种uva(acm)问题的解决方案。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
uva532 Dungeon Master的源代码,并且AC了
这是UVA133 TheDoleQueue救济金发放问题,经典的算法问题。初学算法的人要对这种算法非常熟悉并且能熟练运用。
tpcw-nyu-uva-client 客户端