B. Jumping Jack

Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.

Input

The input data consists of only one integer x ( - 109 ≤ x ≤ 109).

Output

Output the minimal number of jumps that Jack requires to reach x.

Examples
input
2
output
3
input
6
output
3
input
0
output
0
题意:给你一个点,你从0开始走,每次你可以选择向左或者向右走,从1开始每次必须加一步,问你走到那个点的最小步数;
思路:小于0的话就改成大于0的;首先那些步数相加一定要大于那个点的位置;和减去那个点的位置相差为偶数的话就可以到达,从小判断,详见代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define pi 4*atan(1)
//#pragma comment(linker, "/STACK:102400000,102400000")
int a[];
int main()
{
int x,y,z,i,t;
for(i=;i<;i++)
{
if(i%==)
a[i]=i/*(i+);
else
a[i]=(i+)/*i;
}
while(~scanf("%d",&x))
{
if(x<)x=-x;
for(i=;;i++)
if(a[i]>=x&&(a[i]-x)%==)
break;
printf("%d\n",i);
}
return ;
}

最新文章

  1. APP 接口开发及读取静态缓存
  2. windows下怎么打开psql命令
  3. ORACLE RAC集群的体系结构
  4. 苹果系统直接读写 ntfs 磁盘
  5. Docker Centos安装Mysql5.6
  6. Google 2013 campus test-R1
  7. linux共享内存简析
  8. [Java]局域网五子棋
  9. VS Less Compiler插件使用
  10. JavaScript学习day2 (基本语法上)
  11. html 引入页面公共部分(header、footer)
  12. JavaScript学习-1
  13. 19. pt-query-digest
  14. 根据C#编程经验思考编程核心
  15. 洛谷 P3369 【模板】普通平衡树(Treap/SBT)
  16. oracle相关命令收集-张
  17. dmesg功能介绍
  18. lighttpd - 配置
  19. php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳
  20. GIS空间参考及坐标转换

热门文章

  1. ThinkPHP的增删改查!
  2. ThinkPHP分页用异步来做,玩转分页类!
  3. SVN 配置和使用
  4. angular-translate国际化
  5. Oracle管理监控之使用utl_mail自动邮件报警配置
  6. redis cluster 集群畅谈(三) 之 水平扩容、slave自动化迁移
  7. 关于mysql5.7的一些变化
  8. 转!idea 破解版 安装
  9. UIView动画补充
  10. PhotoSwipe中文API(一)