蒟蒻求助!!!

P1150 Peter 的烟

zengziyuezzy @ 2023-08-05 19:36:22

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

by Rainber @ 2023-08-05 19:37:30

记录?


by Rainber @ 2023-08-05 19:41:07

#include<cstdio>
int main()
{
    int c=0;
    int a,b,i;
    scanf("%d%d",&b,&a);
    for(i=0;i<b;++i)
    {
        c++;
        if(c>=a)
        {
            c-=a;
            b++;
        }
    }
    printf("%d",b);
    return 0;
}

by NaCl_0_9H2O @ 2023-08-09 19:44:42

楼上数据强还是过不了

#include<bits/stdc++.h>
using namespace std;
long long a,b,s,l;
int main(){
    cin>>a>>b;
    while(a>0){
        a--;
        s++;
        if(s/b>=1){
            a+=s/b;
            s%=b;
        }
        l++;
    }
    cout<<l;
    return 0;
}

by cyx156 @ 2023-08-11 09:08:01

楼上是一个一个算,数据大会超时。

其实不用这么麻烦地模拟,可以设个变量代表烟蒂,用除法来算。

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

by PeaceSunset @ 2023-08-11 13:23:54

楼上的太麻烦,数据开太多了

#include<bits/stdc++.h>
using namespace std;

int n,k,ans=0;

int main(){
    cin >> n >> k;
    ans=n;
    while(n>=k){
        int temp=n/k;
        ans+=temp,n=n-k*temp+temp;
    }
    cout << ans;
    return 0;
}

by _xdd_ @ 2023-08-11 17:16:18

#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int ans=n,sum=n;
    while(sum>=k){
        ans+=sum/k;
        sum=sum%k+sum/k;
    }
    cout << ans;
    return 0;
}

|