A13883 | Jumps
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are standing on the $\mathit{OX}$ -axis at point $0$ and you want to move to an integer point $x > 0$ .
You can make several jumps. Suppose you're currently at point $y$ ( $y$ may be negative) and jump for the $k$ -th time. You can:
- either jump to the point $y + k$
- or jump to the point $y - 1$ .
What is the minimum number of jumps you need to reach the point $x$ ?
You can make several jumps. Suppose you're currently at point $y$ ( $y$ may be negative) and jump for the $k$ -th time. You can:
- either jump to the point $y + k$
- or jump to the point $y - 1$ .
What is the minimum number of jumps you need to reach the point $x$ ?
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases.
The first and only line of each test case contains the single integer $x$ ( $1 \le x \le 10^6$ ) — the destination point.
The first and only line of each test case contains the single integer $x$ ( $1 \le x \le 10^6$ ) — the destination point.
输出格式
For each test case, print the single integer — the minimum number of jumps to reach $x$ . It can be proved that we can reach any integer point $x$ .
输入输出样例
输入 #1
5 1 2 3 4 5
输出 #1
1 3 2 3 4
In the first test case $x = 1$ , so you need only one jump: the $1$ -st jump from $0$ to $0 + 1 = 1$ .
In the second test case $x = 2$ . You need at least three jumps:
- the $1$ -st jump from $0$ to $0 + 1 = 1$ ;
- the $2$ -nd jump from $1$ to $1 + 2 = 3$ ;
- the $3$ -rd jump from $3$ to $3 - 1 = 2$ ;
Two jumps are not enough because these are the only possible variants:
- the $1$ -st jump as $-1$ and the $2$ -nd one as $-1$ — you'll reach $0 -1 -1 =-2$ ;
- the $1$ -st jump as $-1$ and the $2$ -nd one as $+2$ — you'll reach $0 -1 +2 = 1$ ;
- the $1$ -st jump as $+1$ and the $2$ -nd one as $-1$ — you'll reach $0 +1 -1 = 0$ ;
- the $1$ -st jump as $+1$ and the $2$ -nd one as $+2$ — you'll reach $0 +1 +2 = 3$ ;
In the third test case, you need two jumps: the $1$ -st one as $+1$ and the $2$ -nd one as $+2$ , so $0 + 1 + 2 = 3$ .
In the fourth test case, you need three jumps: the $1$ -st one as $-1$ , the $2$ -nd one as $+2$ and the $3$ -rd one as $+3$ , so $0 - 1 + 2 + 3 = 4$ .
In the second test case $x = 2$ . You need at least three jumps:
- the $1$ -st jump from $0$ to $0 + 1 = 1$ ;
- the $2$ -nd jump from $1$ to $1 + 2 = 3$ ;
- the $3$ -rd jump from $3$ to $3 - 1 = 2$ ;
Two jumps are not enough because these are the only possible variants:
- the $1$ -st jump as $-1$ and the $2$ -nd one as $-1$ — you'll reach $0 -1 -1 =-2$ ;
- the $1$ -st jump as $-1$ and the $2$ -nd one as $+2$ — you'll reach $0 -1 +2 = 1$ ;
- the $1$ -st jump as $+1$ and the $2$ -nd one as $-1$ — you'll reach $0 +1 -1 = 0$ ;
- the $1$ -st jump as $+1$ and the $2$ -nd one as $+2$ — you'll reach $0 +1 +2 = 3$ ;
In the third test case, you need two jumps: the $1$ -st one as $+1$ and the $2$ -nd one as $+2$ , so $0 + 1 + 2 = 3$ .
In the fourth test case, you need three jumps: the $1$ -st one as $-1$ , the $2$ -nd one as $+2$ and the $3$ -rd one as $+3$ , so $0 - 1 + 2 + 3 = 4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted