20分求助!!!

P1150 Peter 的烟

zzzskcy @ 2022-09-06 21:13:08

rt

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

靓仔疑惑:) 为毛我大号能过


by lixiaolan @ 2022-09-15 21:24:23

将if换为这个试试(我试过,样例对了,但不保证全对) while(y>=k) { y=y-k; ans++; y++; }


by BlueTiger @ 2022-10-11 21:53:52

@zzzskcy

试试这个

#include<iostream>
using namespace std;
int main(){
    int a,b,tot=0,l=0;
    cin>>a>>b;
    while(l>=b){
        l-=b;
        a++;
    }
    while(a>0){
        a--;
        tot++;
        l++;
        if(l>=b){
            l-=b;
            a++;
        }
    }
    cout<<tot<<endl;
    return 0;
}

by sleepwalking1 @ 2022-10-22 08:13:00

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

这个好像更好用


|