11 条题解

  • 4
    @ 2023-4-1 16:42:01
    #include <iostream>
    using namespace std;
    int main()
    {
        int n, m, x = 0, y = 0; // x统计空瓶子的数量, y统计能喝多少瓶
        cin >> n >> m;
        for (int i = 1; i <= m / n; i++) // m/n表示能用钱买的
        {
            x += 1; // 喝完一瓶x加一
            if (x == 2) // 够两个空瓶子时
            {
                y += 1; // 换一瓶
                x = 0;
                x += 1; // 喝完一瓶又加一
            }
            y += 1; // 用钱买的
        }
        cout << y;
        return 0;
    }
    
    • 3
      @ 2024-1-15 14:06:08

      非常简单的小测试

      print(3)
      
    • 3
      @ 2023-10-12 21:49:51
      #include <iostream>
      using namespace std;
      int main()
      {
          cout << 3;
          return 0;
      }//推荐率:100%
      
      • 3
        @ 2023-7-27 21:09:30

        如果大家做多了这种换汽水的题,会发现答案=可以买的汽水瓶数 * 2 - 1。所以代码就可以“简化”成这样:image (已AC)

        • 1
          @ 2024-1-29 19:03:14

          乱编一通正儿八经的代码,走你~~~

          #include<iostream>
          using namespace std;
          int num=0;
          int a(int sum){
              if(sum==2){
                  return 1;
              }
              return a(sum/2);
          }//核心
          int main(){
              int n,m,sum1=0;
              cin>>n>>m;
              sum1=m/n;
              cout<<a(m/n)+sum1;
              return 0;
          }//用函数浅试了一下,没想到过了
          
          • 1
            @ 2023-11-21 19:35:01

            没测试过的人版:

            步骤一 步骤二 步骤三
            算出不换可以喝几瓶 兑换 递归重复

            先上核心函数递归代码

            int p(int x)
            {
            	j=(x/2+x%2);
            	if(j==1)
            	  return 1;
            	return x/2+p(j);
            }
            

            总代码!

            #include <bits/stdc++.h>
            using namespace std;
            int n,m,j;
            int p(int x)
            {
            	j=(x/2+x%2);
            	if(j==1)
            	  return 1;
            	return x/2+p(j);
            }
            int main()
            {
            	cin>>n>>m;
            	cout<<p(m/n)+m/n;
            	return 0;
            }
            

            测试过的人的变态版


            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
               cout<<3;
               return 0;
            }
            
            • 1
              @ 2023-7-19 11:06:25

              正常版

              #include <iostream>
              using namespace std;
              int n,m,x,sum,y;//x表示现有的饮料数,sum是能喝到的总数,y是暂时无法兑换的空瓶。
              int main()
              {
                  cin>>n>>m;x=m/n;//m/n是买到的饮料。
                  while(x!=0){//x等于0时没有饮料,便无法兑换。
                      sum+=x;//能喝到的总数增加。
                      if(x%2==0)x=x/2;//能整除就直接兑换。
                      else{
                          x=x/2;y++;//否则就把空瓶数增加1。
                      }
                      if(y==2){
                          x++;y=0;//空瓶数为2继续兑换。
                      }
                  }
                  cout<<sum;
                  return 0;
              }
              
              if(x%2==0)x=x/2;
              else{
                  x=x/2;y++;
              }
              

              可以变成

              x=x/2;
              if(x%2==1)y++;
              

              变态版

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

              全部AC请放心食用

              • 1
                @ 2023-4-5 19:49:29
                #include <bits/stdc++.h>
                using namespace std;
                int n,m,x,sum=0;
                int main()
                {
                    cin>>n>>m;
                    sum+=m/n;
                    x+=m/n;
                    while(x)
                    {
                        sum+=x/2;
                        x=x/2;
                    }
                    
                    cout<<sum;                 
                    return 0;
                }
                
                • @ 2023-4-5 19:51:02

                  先喝买的

                • @ 2023-4-5 19:52:02

                  再换,再喝,再换,再喝,再换,再喝......

                • @ 2023-6-27 16:33:09

                  你的代码过不了样例

              • 0
                @ 2023-8-23 9:53:28

                偷个鸡

                #include <iostream>
                using namespace std;
                int main()
                {
                    cout<<3;
                }
                
                • 0
                  @ 2023-7-28 18:34:55

                  (个人想法请勿自误)这道题应该多给几个评测数据。因为我做的代码是不全的(看完大家的题解才知道),但是却通过了……所以建议管理员多加几分测试数据,其他只有一个测试数据的题也是,避免偶然性😄

                  • -6
                    @ 2022-4-24 16:08:24

                    鼓励大家写题解,但注意题解格式。

                    给代码两端加上这个会舒服一些

                    ```cpp

                    你的代码

                    ```

                    </span>

                    这个点在键盘的左上角tab上面那个键,注意切换输入法

                    #include<iostream>
                    using namespace std;
                    int main()
                    {
                        int n;
                        cin>>n;//这是一个注释
                        return 0;
                    } 
                    

                    请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

                    抄袭题解一经发现直接取消成绩。

                    • 1

                    信息

                    ID
                    373
                    时间
                    1000ms
                    内存
                    16MiB
                    难度
                    3
                    标签
                    递交数
                    804
                    已通过
                    413
                    上传者