50 条题解

  • 69
    @ 2022-8-9 21:08:10

    兄弟们,又是一道费脑子的题目,可以画个图(不然纯脑子,可能会炸开)得出 for 循环的范围是从 1 ~ (i * 2 < n)然后每次将 i 增加1,再按题目意思来判断,求出最大值,上代码吧!~

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, max = 0;
        cin >> n;
        for (int i = 1;i * 2 < n; i++)
        {
            if ( (n - 2 * i) * (n - 2 * i) * i > max) 
                max = (n - 2 * i) * (n - 2 * i) * i;
        }
        cout << max;
        return 0;
    }
    
  • 23
    @ 2022-5-22 20:19:21

    题目意思,可以如下图会更直观一些 OzMHL6.png

    裁剪部分的正方形边长最小是1厘米,最大不超过大正方形的一半,即 裁剪边长*2 < 大正方形边长

    使用循环遍历,挨个进行判断,找出最大面积就可以啦,注意maxx初始化0,还有体积公式:

    体积=底面积=(底面边长底面边长)体积=底面积*高=(底面边长*底面边长)*高

        for(int i=1;i*2<n;i++){
            s = (n-2*i)*(n-2*i)*i;
            if(s>=maxx){
                maxx=s;
            }
        }
    
    • @ 2022-8-9 21:09:04

      牛牛啊,我思路跟你一样耶

    • @ 2023-8-9 16:15:44

      666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666

    • @ 2023-8-9 17:11:39

      懂了,谢大神

    • @ 2023-8-14 19:49:11

      6666666

    • @ 2023-8-24 20:12:59

      我懂了,谢大神🎉️

  • 14
    @ 2023-5-1 17:56:59

    这位大哥(17个赞)([hetao794786 ][LV 10]@ 8 个月前),您AC了吗?看看变量max这个变量是不是跟语句冲突了?看看我的,复制费用:点个赞。

    #include <bits/stdc++.h>
    using namespace std;
    int n, maxx;
    int main()
    {
    cin >> n;
    for (int i = 1; i * 2 < n; i++)
    {
    if ((n - 2 * i) * (n - 2 * i) * i > maxx)
    {
    maxx = (n - 2 * i) * (n - 2 * i) * i;
    }
    }
    cout << maxx << endl;
    return 0;
    
    • @ 2023-8-24 20:18:46

      是不是你搞反了???

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n, max = 0;
          cin >> n;
          for (int i = 1;i * 2 < n; i++)
          {
              if ( (n - 2 * i) * (n - 2 * i) * i > max) 
                  max = (n - 2 * i) * (n - 2 * i) * i;
          }
          cout << max;
          return 0;
      }
      #  100 **Accepted**
      
  • 6
    @ 2023-8-29 8:02:45

    //已AC,点个赞再抱走(其实很容易理解❤️ )

    #include <iostream>
    using namespace std;
    int main(){
        int n,a,b;
        cin >> n;
        a = (n - 2) * (n - 2);
        b = (n - 4) * (n - 4) * 2;
        if(a > b)
        {
            cout << (n - 2) * (n - 2);
        }
        if(b > a)
        {
            cout << (n - 4) * (n - 4) * 2;
        }
        return 0;
    }
    
    • @ 2023-8-29 8:03:27

      确实简单

    • @ 2024-2-3 17:08:29

      好像还可以简化,如下:

      #include <iostream>
      using namespace std;
      int main(){
          int n,a,b;
          cin >> n;
          a = (n - 2) * (n - 2);
          b = (n - 4) * (n - 4) * 2;
          if(a > b)
          {
              cout <<a;
          }
          if(b > a)
          {
              cout <<b;
          }
          return 0;
      }
      
      也可以AC哦!~
      ```@[](/user/20991)
      
  • 4
    @ 2023-8-17 13:04:00

    #include <iostream> using namespace std; int main() { int n,hm=0; cin>>n; for (int i=1;i2<=n;i++) { if ((n-i2)(n-i2)i>m) { hm=(n-i2)(n-i2)*i; }

    }
    cout<<m;
    return 0;
    

    }

    这道题很简单,画个图就行了,不多说了。把赞留下!!!!!

    • @ 2023-8-24 20:15:51

      你管这叫简单????????????????????????

  • 4
    @ 2023-8-11 13:57:21
    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int n, v, s, max_v = 0;
        cin >> n;
        
        for (int i = 1; i <= n / 2; i++)
        {
            s = (n - 2 * i) * (n - 2 * i);
            v = s * i;
            if (v > max_v)
            {
                max_v = v;
            }
        }
    
        cout << max_v;
    
        
        return 0;
    }
    
    
    • 4
      @ 2023-8-7 9:30:25

      bug ///------------------------------- #include<bits/stdc++.h> int main(){std::cout<<128;}

      • 2
        @ 2024-3-16 12:41:02

        好简单

        #include <iostream>
        using namespace std;
        int main()
        {
            cout<<128;
        }
        
        • 2
          @ 2024-1-25 14:22:57
          首先判断有多少种可能的情况
          int n,sum=0;
          cin>>n;
          for (int i=1;i<n;i++)
          {
              if (n-(i*2)>0)
              {
                  sum++;
              }
          }
          
          其次计算每种情况时的体积并用数组储存
          int v[sum];
          for (int m=1;m<=sum;m++)
          {
              v[m-1]=(n-(2*m))*(n-(2*m))*m;//因为边长必须非负,所以当2×m>0时记录体积。
          }
          
          最后求最大值并输出
          //判断体积最大值。
          int max1=v[0];
          for (int m=0;m<sum;m++)
          {
              if (v[m]>max1)
              {
                  max1=v[m];
              }
          }
              cout<<max1;
              return 0;
          

          分步去做就简单多了!!!

          • 2
            @ 2022-8-17 12:23:27

            真的非常强烈建议各位画个图看看,(其实纯脑补也行)不多说,直接上代码

            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                int n,x=0;
                cin>>n;
                for (int i=1;i*2<=n;i++)
                {
                    if ((n-i*2)*(n-i*2)*i>x)
                    {
                        x=(n-i*2)*(n-i*2)*i;
                    }
            
                }
                cout<<x;
                return 0;
            
            }
            
          • 1
            @ 2024-2-19 14:42:25
            for (int i = 1;i<n/2;i++)
                {
                    s = (n-2*i)*(n-2*i)*i;
                    if (s>x)
                    {
                        x = s;
                    }
                }
            
            • 1
              @ 2023-8-30 17:44:53

              #include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m = n / 6; cout << (n - 2 * m) * (n - 2 * m) * m; return 0; } //其实这道题很简单,你只需要知道一个公式:当大正方形的边长=小正方形(剪下的)边长*6,这道题就非常简单了,上代码!~

              • 0
                @ 2024-3-14 21:32:29

                #include <iostream> using namespace std; int main() { cout<<128; }

                • 0
                  @ 2024-3-10 14:06:30
                  
                  

                  #include <bits/stdc++.h> using namespace std; int main() { int n,s=0; cin>>n; for (int i=1;i2<n;i++) { if (s<(n - i2) * (n - i2) * i ) s=(n - i2) * (n - i*2) * i ; } cout<<s; return 0; }

                  
                  
                  • 0
                    @ 2023-9-8 16:54:49

                    自己的一个思路,就是一直枚举,判断这次情况的面积大小,再和之前的最大值比较。 面积判断的if语句是从题目列的算式提取的,但我也不知道为什么这么写,求大佬解释! #刚开始做有点懵,看了几位大佬的题解还是不太理解,就自己尝试编,编完就理顺了......

                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        int a,v=0;
                        cin>>a;
                        for (int i=1;i<a/2;i++)
                        {
                            if ((a-i*2)*(a-i*2)*i>v)
                            {
                                v=(a-i*2)*(a-i*2)*i;
                            }
                        }
                        cout<<v;
                        return 0;
                    }
                    
                    • 0
                      @ 2023-8-29 18:22:05

                      m是几?

                      • 0
                        @ 2023-8-26 16:53:12

                        #include <bits/stdc++.h> using namespace std; int main() { int n, a = 0; cin >> n; for (int i = 1;i * 2 < n; i++) { if ( (n - 2 * i) * (n - 2 * i) * i< a) a = (n - 2 * i) * (n - 2 * i) * i; } cout << a; return 0; }

                        大家好-。- 我故意错了一个地方(·:请你们找出来?! (哦~我真坏(·:) 啊哈哈哈~~~

                        • 0
                          @ 2023-8-25 20:15:43
                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              int n,sum,num;
                              cin >> n;
                              sum=(n-2)*(n-2)*1;
                              num=(n-4)*(n-4)*2;
                              if(sum>num)
                              {
                                  cout << sum;
                              }
                              else
                              {
                                  cout << num;
                              }
                              return 0;
                          }```AC
                          

                          不知道,反正是AC。

                          • 0
                            @ 2023-8-20 12:05:54
                            #include <iostream>
                            using namespace std;
                            int main()
                            {
                                int a,c,d = 0;
                                cin>>a;
                                c = a/2;
                                int b[c];
                                for (int i = 1;i<=c;i++)
                                {
                                    b[i-1]=(a-i)*(a-i)*i;
                                }
                                for (int i = 0;i<c;i++)
                                {
                                    if (d<b[i])
                                    {
                                        d = b[i];
                                    }
                                }
                                cout<<d/2;
                            }
                            
                            • 0
                              @ 2023-8-8 23:00:26
                              #include <bits/stdc++.h>
                              using namespace std;
                              int main()
                              {
                                  int n,y,m;
                                  cin>>n;
                                  y=(n-2)*(n-2);
                                  m=(n-4)*(n-4)*2;
                                  if(y>=m)
                                  {
                                      cout<<y;
                                  }
                                  else
                                  {
                                      cout<<m;
                                  }
                                  return 0;
                              }
                              

                              【入门】纸盒的最大体积是多少?

                              信息

                              ID
                              347
                              时间
                              1000ms
                              内存
                              16MiB
                              难度
                              4
                              标签
                              递交数
                              4983
                              已通过
                              2264
                              上传者