• UVA 1524


    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
    ", sum);
        }
        return 0;
    }

  • 相关阅读:
    Postman的使用和测试
    Django报错 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
    MySQL 修改字段类型或长度
    mysql导入导出sql文件
    Django 无法同步数据库model相应字段问题
    Django objects.all()、objects.get()与objects.filter()之间的区别介绍
    inconsistent use of tabs and spaces in indentation
    JavaScript 计时器
    JavaScript--编程题
    JavaScript--Array 数组对象
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770937.html
Copyright © 2020-2023  润新知