34 条题解

  • -1
    @ 2024-4-20 23:43:27

    这道题其实不是灰常难,跟着题干就可以轻轻松松变出AC代码,这个多项式其实但凡是一个学过绝对值的都可以看懂,和上节课的一道题灰常像。

    • -1
      @ 2024-3-27 21:15:39
      #include
      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);
      }
      

      已AC

      • -1
        @ 2024-1-6 17:06:02
        #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
          @ 2023-12-29 20:53:37
          #include <bits/stdc++.h>
          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
            @ 2023-12-29 20:53:05
            #include <bits/stdc++.h>
            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
              @ 2023-12-8 19:20:57
              #include <iostream>
              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
                @ 2023-10-22 20:04:45
                #include <iostream>
                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);
                }
                
                • -1
                  @ 2023-9-9 17:26:33
                  #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
                    @ 2023-9-7 21:05:03
                    #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
                      @ 2023-5-20 21:29:01

                      先上代码吧

                      #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 多项式的值。这个函数接受两个整数参数 nx,分别表示多项式的阶数和给定的正整数。

                      在函数内部,我们使用递归来计算多项式的值。对于 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 函数中,我们首先读取输入的 nx。然后调用 hermite 函数来计算 Hermite 多项式的值,并将结果存储在变量 result 中。最后,我们输出 result

                      通过这样的实现,我们可以根据给定的正整数 x 和阶数 n 求解对应的 Hermite 多项式的值。时间复杂度取决于阶数 n,是指数级别的。空间复杂度是递归调用栈的大小,也是指数级别的。

                      这样,我们就完成了题目要求,根据给定的正整数 x 和阶数 n 求解 Hermite 多项式的值,并输出结果。

                      • -1
                        @ 2023-3-12 12:21:54

                        先要感谢一下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);
                        }
                        
                        • @ 2023-5-14 14:29:23

                          直接if也可以,return语句执行后直接结束函数的

                      • -1
                        @ 2023-3-11 15:22:11
                        #include <iostream>
                        using namespace std;
                        int h(int n,int x)//。叮咚,你订购的题解来啦,请支付一个赞的邮费,谢谢!
                        { 
                            if(n==0)
                            {
                                return 1;
                            }
                            else if(n==1)
                            {
                                return 2 * x;
                            }
                            else
                            {
                                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);
                        }
                        
                        • -1
                          @ 2023-3-11 6:51:57
                          #include <bits/stdc++.h>
                          using namespace std;
                          int function(int n, int x){
                              if (n == 0) return 1;
                              if (n == 1) return 2 * x;
                              return 2 * x * function(n - 1, x) - 2 * (n - 1) * function(n - 2, x); 
                          }
                          int main(){
                              int n, x; cin >> n >> x; cout << function(n, x); return 0;
                          }
                          

                          棍子战术

                          • -1
                            @ 2023-3-10 20:24:19

                            P1005 Hermite 多项式

                            题目描述

                            求 Hermite 多项式的值。

                            image

                            对给定的正整数 xn,求多项式的值。


                            这种题最为简单,都给了判断条件和相关代码,直接抄上去。

                            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
                          上传者