UVALive 2034 Hot or Cold?【数学】

来源:互联网 发布:淘宝权重怎么提升 编辑:程序博客网 时间:2024/06/03 07:50

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

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

给出一个n次多项式,这个n次多项式是温度关于时间的函数,现在给出起始时间和终止时间,求这段时间的平均的温度


对这个多项式求从初始到终止的积分值。最后除去总时间,即为所求...


#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int n;while(scanf("%d",&n),n){double p[105]={0};for(int i=n;i>=0;--i){scanf("%lf",&p[i]);}double bg,ed,x[105]={0},ans=0;scanf("%lf%lf",&bg,&ed);for(int i=n;i>=0;--i){x[i+1]=p[i]/(i+1);ans+=x[i+1]*pow(ed,i+1);ans-=x[i+1]*pow(bg,i+1);}printf("%.3lf\n",ans/(ed-bg));}return 0;}





0 0