大佬们代码测试点2和3超时,肿么办

P1150 Peter 的烟

Hopoyage @ 2023-09-17 13:36:25

#include<iostream>
using namespace std;
int main(){
    int n,k,sum = 0,temp;
    cin >> n >> k;
    sum += n;
    FLAG:temp = n/k;
    sum += temp;
    if(temp / k >= 1){goto FLAG;}
    cout << sum;
    return 0;
}

by chen_z_k_2048 @ 2023-09-17 13:58:21

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

这样不就行了吗?


by linwanzhou @ 2023-09-17 19:49:45

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

简单明了


|