CF1455B.Jumps

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are standing on the OX\mathit{OX}-axis at point 00 and you want to move to an integer point x>0x \gt 0.

You can make several jumps. Suppose you're currently at point yy (yy may be negative) and jump for the kk-th time. You can:

  • either jump to the point y+ky + k
  • or jump to the point y−1y - 1.

What is the minimum number of jumps you need to reach the point xx?

你站在 OX\mathit{OX}-轴上的点 00 处,希望移动到一个正整数点 x>0x > 0。

你可以进行若干次跳跃。假设你当前位于点 yy(yy 可能为负数),且这是第 kk 次跳跃。那么你可以:

  • 跳跃至点 y+ky + k;
  • 或跳跃至点 y−1y - 1。

到达点 xx 所需的最少跳跃次数是多少?

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The first and only line of each test case contains the single integer xx (1≤x≤1061 \le x \le 10^6) — the destination point.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。

每个测试用例仅有一行,包含一个整数 xx(1≤x≤1061 \le x \le 10^6)—— 目标点。

输出格式

For each test case, print the single integer — the minimum number of jumps to reach xx. It can be proved that we can reach any integer point xx.

对于每个测试用例,输出一个整数——到达 xx 所需的最少跳跃次数。可以证明,我们总能到达任意整数点 xx。

输入输出样例

  • 输入#1

    5
    1
    2
    3
    4
    5

    输出#1

    1
    3
    2
    3
    4

说明/提示

In the first test case x=1x = 1, so you need only one jump: the 11-st jump from 00 to 0+1=10 + 1 = 1.

In the second test case x=2x = 2. You need at least three jumps:

  • the 11-st jump from 00 to 0+1=10 + 1 = 1;
  • the 22-nd jump from 11 to 1+2=31 + 2 = 3;
  • the 33-rd jump from 33 to 3−1=23 - 1 = 2;

Two jumps are not enough because these are the only possible variants:

  • the 11-st jump as −1-1 and the 22-nd one as −1-1 — you'll reach 0−1−1=−20 -1 -1 =-2;
  • the 11-st jump as −1-1 and the 22-nd one as +2+2 — you'll reach 0−1+2=10 -1 +2 = 1;
  • the 11-st jump as +1+1 and the 22-nd one as −1-1 — you'll reach 0+1−1=00 +1 -1 = 0;
  • the 11-st jump as +1+1 and the 22-nd one as +2+2 — you'll reach 0+1+2=30 +1 +2 = 3;

In the third test case, you need two jumps: the 11-st one as +1+1 and the 22-nd one as +2+2, so 0+1+2=30 + 1 + 2 = 3.

In the fourth test case, you need three jumps: the 11-st one as −1-1, the 22-nd one as +2+2 and the 33-rd one as +3+3, so 0−1+2+3=40 - 1 + 2 + 3 = 4.

在第一个测试用例中,x=1x = 1,因此你只需要一次跳跃:第 11 次跳跃从 00 到 0+1=10 + 1 = 1。

在第二个测试用例中,x=2x = 2。你至少需要三次跳跃:

  • 第 11 次跳跃从 00 到 0+1=10 + 1 = 1;
  • 第 22 次跳跃从 11 到 1+2=31 + 2 = 3;
  • 第 33 次跳跃从 33 到 3−1=23 - 1 = 2;

两次跳跃是不够的,因为仅存在以下四种可能情形:

  • 第 11 次跳跃为 −1-1,第 22 次跳跃为 −1-1 —— 你将到达 0−1−1=−20 -1 -1 =-2;
  • 第 11 次跳跃为 −1-1,第 22 次跳跃为 +2+2 —— 你将到达 0−1+2=10 -1 +2 = 1;
  • 第 11 次跳跃为 +1+1,第 22 次跳跃为 −1-1 —— 你将到达 0+1−1=00 +1 -1 = 0;
  • 第 11 次跳跃为 +1+1,第 22 次跳跃为 +2+2 —— 你将到达 0+1+2=30 +1 +2 = 3;

在第三个测试用例中,你需要两次跳跃:第 11 次为 +1+1,第 22 次为 +2+2,即 0+1+2=30 + 1 + 2 = 3。

在第四个测试用例中,你需要三次跳跃:第 11 次为 −1-1,第 22 次为 +2+2,第 33 次为 +3+3,即 0−1+2+3=40 - 1 + 2 + 3 = 4。

输入解题思路,AI测评打分。不知道怎么写?

首页