码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 10268 - 498-bis

时间:2015-08-18 12:11:03      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

題目:計算多項式的導數值,498類似物。

分析:公式,遞推。這裡利用遞推公式求解。

            如果求多項式的值則:fn(x)= Σ [ a(n-j) * x^j ],(0≤j≤n)令A(i) =  Σ [ a(i-j) * x^j ];

            这里得到递推公式为:f`n+1(x)= Σ [ A(n-i) * x^i ],(0≤i≤n);

            (证明:Σ [ A(n-i) * x^i ] = Σ Σ [ a(n-i-j) * x^(i+j) ] = Σ(a(i-1)*x^i + ... + a0*x^n)= Σ(i+1)a(n-i)x^i,成立)

            利用递推公式求解即可。

說明:好久没有刷题了╮(╯▽╰)╭。

#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
	int x, a, temp;
	while (scanf("%d",&x) != EOF) {
		getchar();
		temp = getchar();
		int sum = 0, ans = 0;
		while (temp != '\n' && temp != EOF) {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&a);
				ans = ans * x + sum;
				sum = sum * x + a;
			}
			temp = getchar();
		}
		printf("%d\n",ans);
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

UVa 10268 - 498-bis

标签:

原文地址:http://blog.csdn.net/mobius_strip/article/details/47747171

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!