CF1455B Jumps(思维+模拟)

CF1455B Jumps(思维+模拟)

在这里插入图片描述
在这里插入图片描述

题目大意:

你站在x轴的原点,要求你到某一点去,你每次进行移动只能进行 +k 或者 -1的操作k为你当前的操作次数。问最少操作次数使得你到达终点。

思路:

显然,我们可以利用等差数列的前n项和,得出何时大于等于n(终点坐标),我们首先模拟直接路过终点,也就是超过终点,此时如果我们距离终点的距离为1,那么操作次数加一即可,如果相等即可直接输出,其他相差的次数我们可以通过改变路途中的任一点来实现,假设我们在第k次操作走到了终点的前面,那么我们可以改变的值的区间即为[2, k + 1],也就是说改变其中的值一定能到达终点,且操作次数不变。

#include<iostream>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
const int p = 1e9 + 7;
typedef pair<int, int> pii;
const int N = 1e6+10;
int a[N];

int main() {
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int h = 0;
		int x = 0;
		for (int i = 1; i * (i + 1) < n * 2; i++)h = i * (i + 1) / 2, x = i;
		x++;
		h = x * (x + 1) / 2;
		if (h == n)cout << x << endl;
		else if (h == n + 1)cout << x + 1 << endl;
		else {
			cout << x << endl;
		}
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
股价的跳空是指股票价格在连续交易日之间出现大幅度的价格差异。在Python中,可以使用一些库和函数来计算股价的跳空。 引用\[2\]中提到了使用tl.jump.calc_jump_line()函数来获取跳空能量大于阈值的缺口。这个函数可以帮助我们筛选出跳空能量较大的缺口。例如,可以设置一个跳空能量筛选阈值,如2.8,然后使用该函数来计算跳空缺口。 引用\[3\]中提到了tl.jump.calc_jump_line_weight()函数,与上面使用的calc_jump_line()函数不同之处在于它根据时间权重重新计算了跳空能量。这意味着根据时间线性加权的结果,较早的跳空缺口的能量可能会被降低,而较近的跳空缺口的能量仍然保持不变。 因此,如果你想在Python中计算股价的跳空,可以使用这些函数来筛选和计算跳空缺口的能量。 #### 引用[.reference_title] - *1* [lstm预测股票_股票相关性与lstm预测误差](https://blog.csdn.net/weixin_26750511/article/details/109070595)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [第13节 量化技术分析应用](https://blog.csdn.net/weixin_31901801/article/details/114431033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值