94 条题解

  • -1
    @ 2024-1-27 13:58:55

    E=mcE=mcst=>start: Start:>[https://www.zybuluo.com (https://www.zybuluo.com/) io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end st->io->op->cond cond(yes)->e cond(no) ->sub->io

    • -1
      @ 2024-1-27 13:57:56

      $E=mc2$ st=>start: Start:>[https://www.zybuluo.com (https://www.zybuluo.com/) io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end st->io->op->cond cond(yes)->e cond(no) ->sub->io

      • -1
        @ 2024-1-27 13:55:29
        • [ ] 1
        • -1
          @ 2024-1-20 15:06:53

          st=>start: Start:>https://www.zybuluo.com io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end

          st->io->op->cond cond(yes)->e cond(no)->sub->io

          • -1
            @ 2024-1-20 15:02:36

            $E=mc2 st=>start: Start:>https://www.zybuluo.com io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end

            st->io->op->cond cond(yes)->e cond(no)->sub->io

            • -1
              @ 2024-1-19 17:39:06

              $E=mc2 st=>start: Start:>https://www.zybuluo.com io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end

              st->io->op->cond cond(yes)->e cond(no)->sub->io

              • -1
                @ 2024-1-13 22:01:52
                哈哈哈第一次发题解有点紧张,如果哪里有错请大家指出!
                #include<bits/stdc++.h>
                using namespace std;  直接万能头文件
                int hetao(int n)  定义函数
                {
                    if(n==1)
                    {
                        return 1;
                    }
                    if(n==2)
                    {
                        return 1;
                    }
                    if(n==3)
                    {
                        return 1;  前三个全部返回1
                    }
                    return hetao(n-1)+hetao(n-2)+hetao(n-3);
                }      这里因为规律是前三个数加起来的和,
                       所以要这样写
                int main()
                {
                    int n;        主函数就是直接
                    cin>>n;       定义输入加运算三步走
                    cout<<hetao(n);
                }
                哈哈哈这就是我的见解哪里不妥请各位帅哥美女们提出xiè xiè la!
                
                • -1
                  @ 2024-1-13 20:47:26
                  #include<bits/stdc++.h>
                  using namespace std;
                  int n,a[35];
                  int main(){
                      cin>>n;
                  a[1]=1;
                  a[2]=1;
                  a[3]=1;
                  for(int i=4;i<=30;i++)
                  {
                  a[i]=a[i-1]+a[i-2]+a[i-3];
                  }
                  cout<<a[n];
                  
                      return 0;
                  }```简单易懂款,谢谢使用(c++17 O2)
                  
                  • -3
                    @ 2023-10-6 11:16:56

                    只放核心,其他你行!

                    int yb(int i){//所有变量、函数名你叫啥都行
                        if(i==1) return 1;
                        if(i==2) return 1;
                        if(i==3) return 1;//前三项不符合规律,作为结束点
                        //也可以 if(i==1||i==2||i==3) return 1;
                        return yb(i-1)+yb(i-2)+yb(i-3);//规律:前三项的和等于这一项的值
                    }
                    

                    记得写 return 0;保持好习惯!

                    • -3
                      @ 2023-10-5 21:47:57
                      int func(int i){//不许抄!
                          if(i==1||i==2||i==3)return 1;//终止条件//不许抄!
                          return func(i-1)+func(i-2)+func(i-3);//递归公式//不许抄!
                      }//不许抄!
                      /*
                      不许抄!
                      */
                      

                      第一项是1,第二项也是1,第三项还是1,其他的第i项等于前三项之和。

                      • -3
                        @ 2023-10-5 20:07:50

                        OK呀,这道题原石也是废常的简单好吧 首先,由题可知前三个数都等于1,所以我们要这样

                        if (i == 1 || i == 2 || i == 3)//前三个返回1
                        {
                            return 1;
                        }
                        

                        然后我们又由题可知,从第四个数开始都等于前三个数相加(如:3=1+1+1,5=3+1+1) 所以得出以下代码

                        return func(i-1)+func(i-2)+func(i-3);
                        

                        最后,废话不多说,上完整代码

                        #include <bits/stdc++.h>//万能头文件,启动!
                        using namespace std;//不要复制
                        int func(int i)//不要复制
                        {
                            if (i == 1 || i == 2 || i == 3)//前三个返回1
                            {
                                return 1;//不要复制
                            }
                            return func(i-1)+func(i-2)+func(i-3);//不要复制
                        }
                        int main()//不要复制
                        {
                            long long i;//别问我为什么用longlong
                            cin >> i;//不要复制
                            cout << func(i);//不要复制
                            return 0;//不要复制
                        }
                        
                        • -3
                          @ 2023-7-22 12:14:38

                          这是记忆化搜索的代码(稍快)

                          #include <iostream>
                          using namespace std;
                          int n,a[35];
                          int func(int m)
                          {
                          if(m==1||m==2||m==3) return 1;
                          else if(a[m]) return a[m];
                          else a[m]=func(m-1)+func(m-2)+func(m-3); return a[m];
                          }
                          int main()
                          {
                          cin >> n;
                          cout << func(n);
                          return 0;
                          }
                          //本人推荐
                          

                          下面是普通代码(程序稍简单)

                          #include <iostream>
                          using namespace std;
                          int n,a[35];
                          int func(int m)
                          {
                          if(m==1||m==2||m==3) return 1;
                          else  return func(m-1)+func(m-2)+func(m-3);
                          }
                          int main()
                          {
                          cin >> n;
                          cout << func(n);
                          return 0;
                          }
                          
                          • -3
                            @ 2023-5-21 19:56:58
                            
                            
                            int func(int i)
                            {
                            if (i == 1) return 1;
                            if (i == 2) return 1;
                            if (i == 3) return 1;
                            return func(i-1) +func(i-2)+func(i-3);
                            }
                            
                            

                            核心代码

                            • -3
                              @ 2023-3-3 21:25:01

                              P1001 找规律

                              题目描述

                              有一列数的排列是如下1,1,1,3,5,9,17,31,57,105,……111359173157105……依次类推下去,请你找到规律并求出这个数列第n项。

                              第一部分 递归求解

                              首先,规律这方面很简单,即为 fib(n) = fib(n - 1) + fib(n - 2) + fib(n - 3)

                              找到了规律,再来看终止条件

                              1 = 1;2 = 1;3 = 1;(三个基础的对吧)

                              (终止条件这部分我用的是if-else if)

                              再加上输入输出,大功告成!!!

                              代码:

                              #include <iostream>//hetao3097453
                              using namespace std;
                              int fib(int n)
                              {
                                  if(n == 1)
                                  {
                                      return 1;
                                  }
                                  else if(n == 2)
                                  {
                                      return 1;
                                  }
                                  else if(n == 3)
                                  {
                                      return 1;
                                  }
                                  else
                                  {
                                      return fib(n - 1) + fib(n - 2) + fib(n - 3);
                                  }
                              }
                              int main()
                              {
                                  int n;
                                  cin >> n;
                                  cout << fib(n) << endl;
                                  return 0;
                              }
                              
                              

                              29行,去缩进大概20行搞定

                              第二部分 递推求解

                              同样找规律,不过代码简单得多,大概有缩进10多行

                              时间紧,这里就不放代码了

                              有兴趣可以自行补充


                              hetao3097453(bililili @ 一钩出站)

                              2023年3月3日


                            信息

                            ID
                            5
                            时间
                            1000ms
                            内存
                            256MiB
                            难度
                            5
                            标签
                            递交数
                            6686
                            已通过
                            2803
                            上传者