首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【UVALive】2034 - Hot or Cold?(数论)

【UVALive】2034 - Hot or Cold?(数论)

作者头像
FishWang
发布2025-08-27 08:55:05
发布2025-08-27 08:55:05
1700
举报

点击打开题目

2034 - Hot or Cold?

Time limit: 3.000 seconds

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

代码语言:javascript
复制
2 
1.0 0.0 0.0 
0.0 1.0 
0

Sample Output

代码语言:javascript
复制
0.333

看懂题就是一个求定积分的题。

代码如下:

代码语言:javascript
复制
#include <cstdio>
#include <cmath>
int main()
{
	int n;
	double num[111];
	double st,endd;
	double ans;
	while (~scanf ("%d",&n) && n)
	{
		ans = 0;
		n++;
		for (int i = 1 ; i <= n ; i++)
			scanf ("%lf",&num[i]);
		scanf ("%lf %lf",&st,&endd);
		for (int i = 1 ; n != 0 ; n-- , i++)
			ans += num[i] * (1.0 / n) * (pow(endd , n) - pow(st , n));
		ans /= (endd - st);
		printf ("%.3lf\n",ans);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2034 - Hot or Cold?
  • Input
  • Output
  • Sample Input
  • Sample Output
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档