求助站外题
  • 板块学术版
  • 楼主xiaoyang111
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/14 11:29
  • 上次更新2023/11/2 13:57:52
查看原帖
求助站外题
890311
xiaoyang111楼主2023/10/14 11:29

形式化题目有点绕,直接说简化题目吧。

你在玩一个游戏,开始在 11 处,你要走到 nn 处。即你要走 n−1n-1 长度。

在游戏里,有两种行走方式:

  • 在原地蓄力 ii 秒后消耗 11 秒跳跃 i2i^{2} 长度。

  • 不蓄力往前走 11 长度,消耗时间 11。

且规定:不能跳过终点,但是可以跳到终点(即可以跳到 nn 处)。

请问最少要多少秒才可以到终点。

样例:

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能帮我找找哪里错了吗。

2023/10/14 11:29
加载中...