31 条题解

  • 24
    @ 2022-8-12 19:08:49

    今天我又又又来了奥,今天的标题好奇怪啊好奇怪,需要找规律的循环?什么玩意?先来缕缕思路!

    1. 用两个 for 语句来遍历成人&儿童的人数
    2. 分别定义 children 和 grownup
    3. 成人的取值范围:从少到多(注意!),1~5(40 / 8)
    4. 儿童的取值范围:从多到少(注意!),13(40 / 3)~ 1
    5. 成人在外循环,儿童在内循环。

    欧克,到这里游戏差不多就结束了,来吧先来一个搞怪的(俏皮,全宇宙最短代码)

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        for(int grownup = 1; grownup <= 40 / 8; grownup++) for(int children = 40 / 3; children >= 1; children--) if(grownup * 8 + children * 3 == 40) cout << grownup << " " << children << endl;
        return 0;
    }
    

    咳咳,来个正经的!上代码!

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        for(int grownup = 1; grownup <= 40 / 8; grownup++) 
            for(int children = 40 / 3; children >= 1; children--)
                if(grownup * 8 + children * 3 == 40) cout << grownup << " " << children << endl;
        return 0;
    }
    

    (因为都只有一个语句,所以可以省略大括号)

  • 13
    @ 2022-12-24 20:18:15
    #include <iostream>
    using namespace std;
    int main()
    {
        for (int i = 1; i < 5; i++)
        {
            if(((40 - 8 * i) % 3 == 0) && ((40 - 8 * i) >= 3))
            {
                cout << i << " " << (40 - 8 * i) / 3;
            }
        }
        return 0;
    }//代码已AC
    
    • 7
      @ 2022-5-23 20:12:31

      分别遍历成人和儿童的人数,满足总价钱等于40的就输出

      成人:从少到多,因此成人的范围为 1~40/8

      儿童:从多到少,因此儿童的范围为 40/3~1

      
       for(int i=1;i<=40/8;i++)//成人的人数
       {
       	for(int j=40/3;j>=1;j--)//儿童的人数
       	{
       		if(i*8+j*3==40) //满足价钱等于40
               {cout<<i<<" "<<j<<endl;}
      	 }
       }
      
      • 1
        @ 2024-2-20 22:35:35

        看见没人写Python题解,今天我就来给大家换换脑子,回顾一下Python。

        for i in range(1,5):#循环,从大人人数开始找对应儿童人数,注意!不能把后面的数写成6,这样儿童就没有了,不符合题意!!!
            a=40#总金额
            b=8*i#大人花的钱
            a=a-b#减去大人门票剩下的钱,也就是儿童门票的总金额
            if a%3==0:#判断剩下的钱是否能整除儿童门票价格,因为题目说的是共花了!!!
                print(i,a//3)#如果成立,输出大人人数和儿童人数
        

        别忘了,把编程语言换成Python哦!!!

        • @ 2024-2-20 22:39:23

          如果有神犇路过,请教教我这种五颜六色的题解是怎么搞出来的?image

      • 1
        @ 2023-12-3 19:58:02

        写一个好理解的

        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            for(int i = 1;i <= 5;i++)
            {
                for(int b = 13;b >= 1;b-=1)
                {
                    if(i*8+b*3==40)
                    {
                        cout << i << " " << b << endl;
                    }
                }
            }
        
        }
        
        • 1
          @ 2023-8-15 12:29:23
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              for(int i = 1; i <= 40 / 8; i++)
              { 
                  for(int j = 40 / 3; j >= 1; j--)
                  {
                      if (i * 8 + j * 3 == 40) 
                      {
                          cout << i << " " << j << endl;
                      }
                  }
              }    
                      
              return 0;
          }
          //依旧是两种写法
          

          #include <bits/stdc++.h> using namespace std; int main() { cout<<2<<" "<<8; return 0; } //依旧是不赞成 老规矩不用❤️ 😄 均以AC 0.0s【虽然并不是0.0s,但它这么写,我也就这样写】

          
          
          • 0
            @ 2024-5-26 18:53:11

            奎若大神又双叒叕没有看评测点数量,全宇宙最短代码给我杀!(我可是有反抄袭的,我只弄关键代码,给孩子一个赞拔qwq)

            cout << 2 << " " << 8;
            

            当然,只需要加上一个框架就行了!

            • 0
              @ 2024-4-2 18:42:55

              #include <iostream> using namespace std; int main() { for (int i = 1; i < 5; i++) { if(((40 - 8 * i) % 3 == 0) && ((40 - 8 * i) >= 3)) { cout << i << " " << (40 - 8 * i) / 3; } } return 0; }//代码已AC

              • 0
                @ 2024-1-24 21:04:50
                #include<iostream>
                using namesace std;
                int main()
                {
                    for(int a=1;a<=40/8;i++)
                    {
                        for(int c=40/3;c>=1;c--)
                        {
                            if(a*8+c*3==40)
                            {
                                cout<<a<<" "<<c<<endl;
                            }
                        }
                    }
                    return 0;
                }
                
                • 0
                  @ 2023-11-20 20:43:28
                  #include <bits/stdc++.h> 
                  using namespace std;
                  int main()
                  {
                  	for(int i=1;i<=5;i++){
                  		for(int j=13;j>=1;j--){
                  			if(i*8+j*3==40){
                  				cout<<i<<' '<<j<<endl;
                  			}
                  		}
                  	}
                      return 0;
                  }
                  
                  • 0
                    @ 2023-11-4 17:26:44

                    没有更短

                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        cout<<"2"<<" "<<"8";
                        return 0;
                    }
                    
                    • 0
                      @ 2023-10-6 12:40:36

                      #include<bits/stdtr1c++.h> using namespace std; int main() { cout<<"2 8"; return 0; }

                      • 0
                        @ 2023-10-6 12:39:32

                        宇宙最短!!!

                        #include<bits/stdtr1c++.h> using namespace std; int main() { cout<<"2 8"; return 0; }

                        
                        
                        • 0
                          @ 2023-10-4 12:14:03
                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              for (int i = 1; i < 5; i++)
                              {
                                  if(((40 - 8 * i) % 3 == 0) && ((40 - 8 * i) >= 3))
                                  {
                                      cout << i << " " << (40 - 8 * i) / 3;
                                  }
                              }
                              return 0;
                          }
                          
                          • 0
                            @ 2023-8-30 15:20:24
                            //挑战全网最简代码,不信就来试试
                            #include <iostream>
                            using namespace std;
                            int main()
                            {
                                cout << 2 << " " << 8;
                                return 0;
                            }
                            
                            • 0
                              @ 2023-8-18 12:10:47
                              #include <iostream>
                              using namespace std;
                              int main()
                              {
                                  for (int j = 1; j < 5; j++)
                                  {
                                      for (int i = 13; i > 0; i--)
                                      {
                                          if (i * 3 + j * 8 == 40)
                                          {
                                              cout << j << " " << i << endl;
                                          }
                                      }
                                  }
                                  return 0;
                              }
                              

                              要注意:成人外循环 儿童内循环 (否则TLE(亲测😕

                              • 0
                                @ 2023-8-17 12:19:21
                                #include <bits/stdc++.h> //万能开头
                                using namespace std;
                                int main()
                                {
                                    for (int i = 1; i <= 40; i++) //枚举成人
                                    {
                                        for (int j = 1; j <= 40 - i; j++) //枚举儿童
                                        {
                                            if (i * 8 + j * 3 == 40)
                                            {
                                                cout << i << " " << j << endl;
                                            }
                                        }
                                    }
                                    return 0;
                                }
                                
                                • 0
                                  @ 2023-8-13 14:24:54

                                  无脑的for循环,不考虑算法和内存(已AC)

                                  #include <bits/stdc++.h>
                                  using namespace std;
                                  int main()
                                  {
                                      for (int i=1;i<=40;i++)//成人
                                      {
                                          for (int j=40;j>=1;j--)//儿童
                                          {
                                              if (i*8+j*3==40)
                                              {
                                                  cout<<i<<' '<<j<<endl;
                                              }
                                          }
                                      }
                                      return 0;
                                  }
                                  
                                  • 0
                                    @ 2023-8-6 11:41:41

                                    挑战一下除注释外最短

                                    #include <iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int sum=40,es=0;
                                        for (int i=1;i<5;i++)//i表示成人人数
                                        {
                                            if ((40-8*i)%3==0)//8*i为成人总消费,40-8*i为儿童总消费,因为循环中i<5,而5*8=40,故儿童至少有1人,无需判断(40-(8*i)/3>=1)等
                                            {
                                                cout<<i<<" "<<(40-8*i)/3<<endl;
                                            }
                                        }
                                        return 0;
                                    }
                                    
                                    • 0
                                      @ 2023-8-5 20:51:46

                                      全网最短(已AC)

                                      #include <bits/stdc++.h>
                                      using namespace std;
                                      int main(){cout<<2<<" "<<8;return 0;}
                                      

                                    信息

                                    ID
                                    348
                                    时间
                                    1000ms
                                    内存
                                    16MiB
                                    难度
                                    4
                                    标签
                                    递交数
                                    2898
                                    已通过
                                    1355
                                    上传者