求助QAQ(Tle6s)

P1423 小玉在游泳

改了改还是不对(~~约等于没改~~) ```c #include<bits/stdc++.h> using namespace std; int main(){ int a=1,b=1; double num=2.0,i,sum; cin>>sum; while(b==1){ if(num>=sum){ b=b-1; cout<<a; } else{ i=num*1.98; a++; } } return 0; } ```
by Kvj123456 @ 2021-10-06 08:53:55


```cpp #include<bits/stdc++.h> #define int long long #define rei register int #define rep(i,x,y) for(rei i = (x);i <= (y);i++) #define per(i,y,x) for(rei i = (y);i >= (x);i--) #define grep(i,x) for(rei i = h[x];i ;i = ne[i]) #define dou double #define mp make_pair #define X first #define Y second #define ls(fadsfdds) t[fadsfdds << 1] #define rs(fadsfdds) t[fadsfdds << 1 | 1] #define len(fasd) (t[fasd].r - t[fasd].l + 1) #define ull unsigned int using namespace std; const int N = 1e5 + 5,M = N << 1,P = 131; int Q; void read(int &x){ int s = 0,f = 1;char ch = getchar(); while(ch > '9' || ch < '0'){if(ch == '-')f = -1;ch = getchar();} while(ch <= '9' && ch >= '0')s = s * 10 + ch - '0',ch = getchar(); x = s * f; } int step; dou p = 2,x; signed main(){ scanf("%lf",&x); while(x > 0)x -= p,step++,p *= 0.98; printf("%lld",step); return 0; } ```
by yhxfzs @ 2021-10-06 08:58:06


快读!!!大佬大佬
by int4096 @ 2021-10-06 08:59:45


``` #include<bits/stdc++.h> using namespace std; int main(){ int a=1; double num=2.0,sum; cin>>sum; while(1){ if(num>=sum){ // b=b-1; ??? 没看懂 cout<<a; return 0; } else{ sum -= num;//每一次减少的距离 num = num*0.98; a++; } } return 0; } ```
by yhxfzs @ 2021-10-06 09:10:12


有些变量是没有必要的吧
by LionShiZi @ 2021-10-06 09:15:28


@[Kvj123456](/user/569914) 很明显了 首先,你不能 ```cpp i*=1.98; ``` 应该改成 ```cpp i+=num; num*=0.98; ``` 在此之外 你TLE是因为: ```cpp num=2.0没有变过 应该是i>=sum作为判断条件 ``` 建议以后用bool来记录
by Luban @ 2021-10-06 09:53:05


@[yhxfzs](/user/207407) 巨佬,甘拜下风
by Kvj123456 @ 2021-10-06 19:09:57


@[可爱小鲁班](/user/113600) 谢谢大佬,回去试一下先
by Kvj123456 @ 2021-10-06 19:10:53


@[yhxfzs](/user/207407) b=b-1相当于retrun 0 我不会用,刚接触没1个月
by Kvj123456 @ 2021-10-06 19:26:04


@[可爱小鲁班](/user/113600) ~~本巨蒻还是没会,不好意思再找dalao了~~ ```c #include<bits/stdc++.h> using namespace std; int main(){ int a=1,b=1; double num=2.0,i,sum; cin>>sum; while(i>=sum){ if(num>=sum){ cout<<a; return 0; } else{ i=num*1.98; a++; } } return 0; } ```
by Kvj123456 @ 2021-10-06 19:34:05


| 下一页