TLE

P1423 小玉在游泳

@[li_zhi_a_wei](/user/1047089) $k$ 先除会导致可能变成 $0$,导致不断减 $0$,就死循环了。
by Falling_Sakura @ 2023-08-20 14:59:20


@[FallingSakura](/user/773503) 谢谢
by li_zhi_a_wei @ 2023-08-20 15:01:42


死循环了,建议用另一个变量代替s;把s的值付给他
by zhexu_Li @ 2023-08-20 15:43:23


k是int类型的,改double吧
by glx123 @ 2023-08-20 16:05:00


@[li_zhi_a_wei](/user/1047089) 你咋做出 P2081和P5396的
by chenyuchen_1 @ 2023-08-27 15:55:45


```cpp #include<iostream> using namespace std; int main() { int step = 0; double distance , sum = 0 , move = 2 , factor = 0.98; cin >> distance; while(sum < distance){ sum = sum + move; move = move * factor; step++; } cout << step; return 0; } ```
by DBL_MAX @ 2024-02-10 14:53:10


|