形式化题目有点绕,直接说简化题目吧。
你在玩一个游戏,开始在 1 处,你要走到 n 处。即你要走 n−1 长度。
在游戏里,有两种行走方式:
且规定:不能跳过终点,但是可以跳到终点(即可以跳到 n 处)。
请问最少要多少秒才可以到终点。
样例:
input1:
3
out1:
2
input2:
5
out2:
3
input3:
114514
out3:
363
代码:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
--n;
int t;
int ans=0;
while (n>3){
t=sqrt(n);
n-=t*t;
ans+=t+1;
}
cout<<ans+n<<endl;
return 0;
}
90pts,dalao能帮我找找哪里错了吗。