5 条题解

  • 3
    @ 2023-2-11 10:30:56

    一天一天过

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int m, k;
        cin >> m >> k;
        //m: 当前手头的钱
    	//k: 每k元送一元 
    	int ans = 0;//过了多少天 
    	int cnt = 0;//花了多少钱 
    	while(1){
    		//花了一块钱,过了一天 
    		m-=1;
    		ans+=1;
    		cnt+=1;
    		//送钱 
    		if(cnt%k==0)
    			m+=1; 
    		if(m==0)
    			break;    	
    	}
    	cout<<ans<<"\n";
        return 0;
    }
    

    k天k天过

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int m, k;
        cin >> m >> k;
        //m: 当前手头的钱
    	//k: 每k元送一元 
    	int ans = 0;//过了多少天 
    	while(1){
    		//花k块钱,过k天 
    		m-=k;
    		ans+=k;
    		m+=1;
    		if(m<k)
    			break;    	
    	}
    	cout<<ans+m<<"\n";
        return 0;
    }
    
    • 2
      @ 2023-2-11 10:12:48
      #include <bits/stdc++.h>;
      using namespace std;
      
      int main()
      {
      	int m,k,n = 0;
      	cin >>m>>k;
      	int b=0,day = 0;
      	for(;m>=1;)
      	{
      		m--;
      		day++;
      		b++;
      		if(b==k)
      		{
      			m++;
      			b=0;
      		}
      	}
      	cout <<day;
      	return 0;
      }
      
      • 1
        @ 2023-6-29 14:29:47

        好像能简洁一点?

        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int a,b,day=0;
        	cin>>a>>b;
        	for(int i=a;i>0;i--)//花钱
        	{
        		day++;
        		if(day%b==0)i++;//加钱
        	}
        	cout<<day;
        	return 0;
        }
        
        • 1
          @ 2023-2-11 11:05:48

          非常详细版

          #include <bits/stdc++.h>
          using namespace std;
          int m,k,nowday,num;//m、k、目前天数、花费金额 
          int main()
          {
              cin>>m>>k;//引进m和k
          	while(1)//无限循环 
          	{
          		num+=1;//每天花费1元 
          		nowday+=1;//目前天数加1天 
          		m-=1;//总钱数减1元 
          		if(num==k)//当花费金额到了赠1元的金额时 
          		{
          			num-=k;//现花费金额清零
          			m+=1;//总钱数加上赠送的1元
          		}
          		if(m==0)//如果没钱了 
          		{
          			break;
          		}
          	}
          	cout<<nowday;
              return 0;
          }
          
          • 0
            @ 2023-10-23 22:09:44
            #include<bits/stdc++.h>
            using namespace std;
            int main()
            {
                int n,m,k,j=0,d=0;
                cin>>m>>k;
                for(int i=m;i>0;i--)
                {
                    d++;
                    if(d==k)
                    {
                        i++;
                        d=0;
                    }
                    j++;
                }
                cout<<j;
            }
            
            • 1

            信息

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