我错哪了???

P1423 小玉在游泳

`double` 类型能用 `++`?
by _venti @ 2024-01-29 19:22:07


还有第四行是中文逗号
by _venti @ 2024-01-29 19:23:05


1.循环条件应为 x>0 2.更新 x 时用 "-" 而不是 "/" 3.ans不用开 `double`
by pig1121 @ 2024-01-29 19:23:33


@[babamunui](/user/762062) 你这a要初始化!要初始化成 **double a = 0;** ```cpp #include <bits/stdc++.h> using namespace std; int main () { double a = 0,x,s=2; cin>>x; while(x<1){ x/=s; s*=0.98; a++; } cout<<a; return 0; } ``` 而且,你没有换行的习惯吗()
by ZZYX_18670145320 @ 2024-01-29 19:24:18


谢谢各位大佬
by babamunui @ 2024-01-29 19:27:17


```cpp #include <bits/stdc++.h> using namespace std; int main () { double x,s=2; long long a=0; cin>>x; while(!(x<1)){ x/=s; s*=0.98; a++; } cout<<a; return 0; } ```
by babamunui @ 2024-01-29 19:33:08


@[ZZYX_18670145320](/user/1192648) 是这样改吗
by babamunui @ 2024-01-29 19:36:35


@[babamunui](/user/762062) 是这样:(结合了其他大佬的想法) ```cpp #include <bits/stdc++.h> using namespace std; int main () { double x,s=2; long long a=0; cin>>x; while(x>0){ x-=s; s*=0.98; a++; } cout<<a; return 0; } ``` 循环条件是x > 0,然后每次循环就要减,就是x -= s。其他的问题就没什么。应该可以AC100。
by ZZYX_18670145320 @ 2024-01-29 20:59:36


谢谢
by babamunui @ 2024-01-30 07:48:28


|