題目:計算多項式的導數值,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;
}