B. Jumping Jack

题目连接:

http://www.codeforces.com/contest/11/problem/B

Description

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.

Sample Input

2

Sample Output

3

Hint

题意

这个人在0点这个位置,每次可以选择往左边或者往右边跳

每次跳了之后,他的跳跃力都会增加1

问你跳到他想要的位置,最小需要跳多少次?

题解:

最简单的就是如果终点一直能够跳过去就到就好了。

如果跳过了的话,如果跳过的距离是偶数的话,可以通过使得(now-x)/2这一步往远离终点的方向跳就好了

如果是奇数的话,那就再跳几步就好了。

代码

#include<bits/stdc++.h>
using namespace std; int main()
{
long long x;
scanf("%lld",&x);
if(x<0)x=-x;
int res = 0;
int tot = 0;
while(tot<x||(tot-x)%2)
{
res++;
tot+=res;
}
cout<<res<<endl;
}

Codeforces Beta Round #11 B. Jumping Jack 数学的更多相关文章

  1. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

  2. 状压dp找寻环的个数 Codeforces Beta Round #11 D

    http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...

  3. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  6. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  7. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  8. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  9. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

随机推荐

  1. python几种装饰器的用法

    用函数装饰函数 这种比较常见首先定义装饰器函数 def cache(func): data = {} @wraps(func) def wrapper(*args, **kwargs): key = ...

  2. 认识我们的太阳系(Solar System)

    一.初识太阳系 如果太阳是一颗篮球,那么我们的地球是什么?? 如果太阳系里最大的行星:木星是一颗足球,那么我们的地球是什么?? 如果我们的地球是一颗排球,那么其他行星是什么?? 由此,我们可以看到,我 ...

  3. Win10搜索不能用

    使用win10进行搜索时,一直显示win10特色的滚动条,但就是检索不出东西,我的主要是检索不到windows的内容: (个人感觉使用win10检索网页内容不太专业,就关闭了Web搜索) 最后有发现网 ...

  4. Ibatis.Net 各类的作用说明学习(三)

    Ibatis中,加载.分析配置及映射文件是在创建SqlMapper实例的时候进行的,另外对数据库的操作,也是在SqlMapper实例上调用方法来完成.创建SqlMapper的实例的方式是: ISqlM ...

  5. spark集群安装[转]

    [转]http://sofar.blog.51cto.com/353572/1352713 ====================================================== ...

  6. FlumeNG介绍及安装部署

    本节内容: Flume简介 Flume NG核心组件 Flume部署种类 Flume单机安装 一.Flume简介 Flume是一个分布式.可靠.高可用的海量日志聚合系统,支持在系统中定制各类数据发送方 ...

  7. IEEEXtreme 极限编程大赛题解

    这是 meelo 原创的 IEEEXtreme极限编程大赛题解 IEEEXtreme全球极限编程挑战赛,是由IEEE主办,IEEE学生分会组织承办.IEEE会员参与指导和监督的.IEEE学生会员以团队 ...

  8. Asp.net Vnext TagHelpers

    概述 本文已经同步到<Asp.net Vnext 系列教程 >中] TagHelpers 是vnext中引入的新功能之一.TagHelper 的作用是类似于发挥在以前版本的 ASP.NET ...

  9. python 库资源大全

    偶然的机会翻到这篇文章,很全面,来源:  Python 资源大全中文版       哪些 Python 库让你相见恨晚? 环境管理 管理 Python 版本和环境的工具 p:非常简单的交互式 pyth ...

  10. 【LOJ】#2205. 「HNOI2014」画框

    题解 我原来根本不会KM 更新每个节点增加的最小值的时候,要忽略那个方访问过的右节点!!! 然后就和最小乘积生成树一样了 代码 #include <iostream> #include & ...