0分求助

P1150 Peter 的烟

liuyuzec @ 2023-07-25 09:33:20

#include<iostream>
using namespace std;
int main()
{
    int n,m=0,a,s=0,b;
    cin>>n>>a;
    while(m+n>a||m>0)
        {
            s+=n;
            n=0;
            m+=n;
            b=m/a;
            n+=b;
            b*=a;
            m-=b;
        }
    cout<<s;
    return 0;
} 

by ML_Galaxy_ @ 2023-07-25 09:55:01

我看不懂你这个

代码如下:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,ans=0,d=0;
    cin>>n>>k;
    ans=n;
    d=n;
    while(d>=k){
        d=d-k;
        d++;
        ans++;
    }
    cout<<ans;
    return 0;
}

by liuyuzec @ 2023-07-25 09:57:31

@ycz0114 感谢大佬


|