90分,c++代码。

P1150 Peter 的烟

MY_gg @ 2021-12-24 22:03:50


#include<bits/stdc++.h>
using namespace std;
long long s;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    s+=n;
    int n1=n;
    n/=k;
    s+=n;
    n1%=k;
    if(n1>=1&&n>=k)
    s+=1;
    printf("%d",s); 
    return 0;
}

by SSqwq_ @ 2021-12-24 22:10:22

烟蒂换的烟还可以产生新的一个烟蒂

你得用循环

@wby0124


by chenruixi @ 2021-12-24 22:10:27

如果模拟最好用循环

方程思想:

k个烟蒂=1根烟+1个烟蒂

所以k-1个烟蒂=1根烟

再试试吧,难度很低的;


by MY_gg @ 2021-12-24 22:21:24

哦,明白了。谢谢!


by liujinhao000 @ 2021-12-26 13:37:06


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

|