80!求救!

P1150 Peter 的烟

xieyunheng @ 2024-11-12 21:45:43

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

int main(){
    int n,k;
    cin>>n>>k;
    int yan=n;
    if(n>=k){
        int y=n/k; 
        yan+=y;
        if(y+n%k>=n){
            int x=y+n%k;
            yan+=x/k;
            if(y+n%k>=n){
               int x=y+n%k;
                yan+=x/k;
            }

        }
    }
    cout<<yan;
    return 0;
}

by chem114514 @ 2024-11-17 16:55:34

#include <iostream>

int totalCigarettes(int n, int k) {
    int totalSmoked = n; // 总共吸过的烟数
    int butts = n;       // 当前拥有的烟蒂数

    while (butts >= k) {
        int newSmokes = butts / k; // 用烟蒂换取的新烟数量
        totalSmoked += newSmokes;   // 更新总吸烟数量
        butts = butts % k + newSmokes; // 更新剩余的烟蒂
    }

    return totalSmoked;
}

int main() {
    int n, k;

    std::cout << "";
    std::cin >> n;

    std::cout << "";
    std::cin >> k;

    int result = totalCigarettes(n, k);

    std::cout << "" << result << std::endl;

    return 0;
}

by Zyqcodeblocks @ 2024-11-20 22:07:36

#include <iostream>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int cnt=0;//可以使用计数器来表示每次吸三根烟后计入一组中,输出时乘k即可
    while(n>=k){
        cnt++;
        n=n-k+1;//每次更新n的数值
    }
    cout<<cnt*k+n;//求出结果,记得加n
    return 0;
}

by NARUTOcjl @ 2025-01-06 20:51:38

满分题解

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

|