34 条题解
-
-1
#include <iostream> #include <bits/stdc++.h> #include <stdio.h> #include <iomanip> using namespace std; int h(int n,int x) { if (n == 0) { return 1; } else if (n == 1) { return 2 * x; } else if (n > 1) { return 2*x* h(n - 1,x) - 2*(n-1)* h(n-2,x); } } int main() { int x,n; cin >> n >> x; cout << h(n,x); return 0; }
-
-1
#include <iostream>//抽象AC using namespace std; #define _ int #define ______________________________ return _ h(_ n,_ x) { if (n == 0) { ______________________________ 1; } else if (n == 1) { ______________________________ 2 * x; } else if (n > 1) { ______________________________ 2*x* h(n - 1,x) - 2*(n-1)* h(n-2,x); } } _ main() { _ x,n; cin >> n >> x; cout << h(n,x); }
-
-1
#include <bits/stdc++.h> using namespace std; int hetmite(int n,int x) { if (n==0) return 1; else if (n==1) return 2*x; else if (n>1) return 2*x*hetmite(n-1,x)-2*(n-1)*hetmite(n-2,x);//按规则来就可以了 return 0;//没有必要,但是不加就会一直警告,很难看,不爽,有强迫症的我把这句加上了。 } int main() { int n,x; cin>>n>>x; cout<<hetmite(n,x);//调用函数 return 0; }
-
-1
先上代码吧
#include <iostream> using namespace std; int hermite(int n, int x) { if (n == 0) return 1; else if (n == 1) return 2 * x; else return 2 * x * hermite(n - 1, x) - 2 * (n - 1) * hermite(n - 2, x); } int main() { int n, x; cin >> n >> x; int result = hermite(n, x); cout << result << endl; return 0; }
在这个代码中,我们定义了一个函数
hermite
来计算 Hermite 多项式的值。这个函数接受两个整数参数n
和x
,分别表示多项式的阶数和给定的正整数。在函数内部,我们使用递归来计算多项式的值。对于
n
等于 0 的情况,直接返回 1。对于n
等于 1 的情况,返回 2x。对于n
大于 1 的情况,使用递推公式2x * h(n-1, x) - 2(n-1) * h(n-2, x)
来计算多项式的值,其中h(n-1, x)
和h(n-2, x)
分别表示n-1
阶和n-2
阶的 Hermite 多项式的值。在
main
函数中,我们首先读取输入的n
和x
。然后调用hermite
函数来计算 Hermite 多项式的值,并将结果存储在变量result
中。最后,我们输出result
。通过这样的实现,我们可以根据给定的正整数
x
和阶数n
求解对应的 Hermite 多项式的值。时间复杂度取决于阶数n
,是指数级别的。空间复杂度是递归调用栈的大小,也是指数级别的。这样,我们就完成了题目要求,根据给定的正整数
x
和阶数n
求解 Hermite 多项式的值,并输出结果。 -
-1
先要感谢一下hetao704482大人的帮助(翻译)!!!
#include <iostream> using namespace std; int h(int n,int x) { if (n == 0) { return 1; } else if (n == 1)//别忘了是else if { return 2 * x; } else if (n > 1) { return 2*x* h(n - 1,x) - 2*(n-1)* h(n-2,x);//*这个返回值的翻译详见704482大人的题解 } } int main() { int x,n; cin >> n >> x; cout << h(n,x); }
-
-1
P1005 Hermite 多项式
题目描述
求 Hermite 多项式的值。
对给定的正整数 x 和 n,求多项式的值。
这种题最为简单,都给了判断条件和相关代码,直接抄上去。
1.需要有俩参数,一个n,一个x.
参考代码
#include <iostream>//hetao3097453 using namespace std; int n,x; int hermite(int n,int x) { if(n == 0) { return 1; } if(n == 1) { return 2 * x; } else { return 2 * x * hermite(n - 1,x) - 2 * (n - 1) * hermite(n - 2,x); } } int main() { cin >> n >> x; cout << hermite(n,x) << endl; return 0; }
hetao3097453(bililili @ 一钩出站)
2023年3月10日
信息
- ID
- 9
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 4262
- 已通过
- 2003
- 上传者