UVA 1524 - Hot or Cold? 【求积分】

F - Hot or Cold?
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

John Smith, who is a member of Academy of Cold Manager (ACM), is in charge of a large-scale cold store. For him, it's a troublesome job. Whenever the temperature in the cold store is too hot or too cold for a long time, the goods will be damaged. And poor Mr. Smith will have to compensate for the loss of the store.

Therefore, Mr. Smith has installed an automatic temperature control system in the store. The system may control the temperature according to the input polynomial and the start time. At each moment, it tries to adjust the temperature equal to the value of the polynomial function. But Mr. Smith still feels worried. Since he could not know the effect beforehand how the system will regulate. At such a worrisome moment, it's lucky for him to call to remembrance that you, an excellent programmer, are willing to offer a program to help him. Making use of this program, he may simply input the polynomial and the parameters of the start time and the end time, and then he will be aware of the average temperature during this period. Now he is relieved from such a bothersome job.

Input

The input file may contain several data sets. Each data set begins with a line containing an integer n(n < 100), which specifies the highest power of the polynomial. A value of 0 for the power indicates the end of input, and this data set should not be processed. In each data set, the following line contains n + 1 real numbers, which tell the coefficients of the polynomial. The sequence of those coefficients is arranged according to the power of items from high to low in the polynomial. If an item of the polynomial does not exist, the corresponding coefficient is 0. And then follows a line consists of 2 real numbers s and e(s < e), indicating the start time and the end time.

Output

For each data set, compute t, the average temperature of the input polynomial from the start time to the end time. Print your answer as a single real number accurate to 3 decimal places on a line by itself. You should not print any more white spaces or blank lines in the output.

Sample Input

2 
1.0 0.0 0.0 
0.0 1.0 
0

Sample Output

0.333
 
     
题意是给你一个多项式的系数,让你函数在[s, e]上的积分的均值。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <iostream>
#define MAX_N   1500
#define MAX(a, b) (a > b)? a: b
#define MIN(a, b) (a < b)? a: b
using namespace std;

double ar[MAX_N], s, e;
double jf(double x, int y) {
    double ans = 0;
    for (int i = 0; i <= y; i++) {
        ans += ar[i]*pow(x, i + 1);
    }
    return ans;
}
int main() {
    int n;
    while (scanf("%d", &n), n) {
        bool flag = true;
        for (int i = n; i >= 0; i--) {
            scanf("%lf", &ar[i]);
            if (ar[i] != 0) flag = true;
        }
        scanf("%lf %lf", &s, &e);
        double temp = 1;
        for (int i = 0; i <= n; i++) {
            ar[i] = ar[i]/(i + 1);
        }
        double sum = jf(e, n) - jf(s, n);
        sum /= (e - s);
        printf("%.3lf\n", sum);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值