第三评测wa 90分 求助

P1150 Peter 的烟

wangshian @ 2023-08-20 09:35:17

我的代码

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

一直卡在第三测试点 求解


by drinktowind @ 2023-08-20 09:42:44

试试输入10和2


by cmpt_xiaoxiao @ 2023-08-20 09:43:12

不需要枚举


by cmpt_xiaoxiao @ 2023-08-20 09:43:49

推推这个公式n+(n-1)/(m-1)


by drinktowind @ 2023-08-20 09:44:46

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

枚举看这里


by cmpt_xiaoxiao @ 2023-08-20 09:45:23

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    long long n,m;
    cin>>n>>m;
    cout<<n+(n-1)/(m-1);
    return 0;
}

by drinktowind @ 2023-08-20 09:45:25

如果有用关注一下谢谢喵


|