只有80分!!!求求你啦求求你啦,帮帮蒟蒻吧

P1150 Peter 的烟

zhao_jiang_zi_han @ 2024-08-18 05:30:20

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

int main()
{
    int n,k;
    cin>>n>>k;
    if(n >= k)
    {
        cout<<n + n / k<<endl;
    }else{
        cout<<n<<endl;
    }
    return 0;
}

by King_and_Grey @ 2024-08-18 07:01:33

@zhao_jiang_zi_han 不是直接输出 `n + (n - 1) / (k - 1)`吗?


by ZZyangchengzhuo @ 2024-08-18 07:05:58

楼上说得对


by apzzzx @ 2024-08-18 07:16:29


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

by apzzzx @ 2024-08-18 07:16:47

@zhao_jiang_zi_han


by apzzzx @ 2024-08-18 07:17:06

求关


by Love_Natsu @ 2024-08-18 08:57:44

你这个代码没有处理合成的烟吸完后剩下的烟蒂还可以再合成的问题,可以这样:

int tmp=0,ans=0;//tmp是烟蒂数
while(n)ans+=n,tmp+=n,n=tmp/k,tmp=tmp%k;
cout<<ans;

by zhao_jiang_zi_han @ 2024-08-18 13:45:31

@apzzzx 已关注,谢谢你的代码


by zhao_jiang_zi_han @ 2024-08-18 13:45:55

@Love_Natsu 谢谢


by zhao_jiang_zi_han @ 2024-08-18 13:46:20

@King_and_Grey 谢谢


by shuiyou1 @ 2024-08-18 14:33:11

@apzzzx 我一开始写的是n+(n/k),我想不通为啥要(n-1)/(k-1),求解答


| 下一页