90第三个帮忙看下呗谢谢啦

P1150 Peter 的烟

huochairenzhishang @ 2024-04-27 20:25:04

include <iostream>

using namespace std; int main() { int smoke, num; int sum = 0; cin >> smoke >> num; sum += smoke; while (smoke >= num) { smoke = smoke / num; sum += smoke; } cout << sum << endl; }


by ZYLZPP @ 2024-04-27 20:44:51

@huochairenzhishang

只有整除num的烟斗被用来换新的

还有smoke%num个烟头剩余,可下次兑换用

而原代码忽略了这部分烟头

应该改为

while (smoke >= num) {
    int more = smoke / num;
    smoke %= num;
    sum += more;
    smoke += more;
}

by huochairenzhishang @ 2024-04-27 20:56:08

@ZYLZPP 谢谢哥啦明白了


|