Codeforces Beta Round #11 B. Jumping Jack 数学
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 数学的更多相关文章
- Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...
- 状压dp找寻环的个数 Codeforces Beta Round #11 D
http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...
- Codeforces Beta Round #10 C. Digital Root 数学
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- 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]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
随机推荐
- 采用dlopen、dlsym、dlclose加载动态链接库【总结】【转】
转自:https://www.cnblogs.com/Anker/p/3746802.html 1.前言 为了使程序方便扩展,具备通用性,可以采用插件形式.采用异步事件驱动模型,保证主程序逻辑不变,将 ...
- ps查看CPU和内存占用前10的进程
内存增序 ps aux --sort rss 内存减序 ps aux --sort -rss cpu增序 ps auxw --sort=%cpu cpu减序 ps auxw --sort=-%cpu ...
- 十三、springboot集成定时任务(Scheduling Tasks)
定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...
- @RequestParam,@PathParam,@PathVariable,@QueryParam注解的使用区别
获取url模板上数据的(/{id})@DefaultValue 获取请求参数的(包括post表单提交)键值对(?param1=10¶m2=20).可以设置defaultValue JA ...
- 15 Defer, Panic, and Recover
Defer, Panic, and Recover 4 August 2010 Go has the usual mechanisms for control flow: if, for, switc ...
- Python [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法
一个搭建在SAE上的Django应用,使用新浪微博提供的Python SDK已经稳定运行一年有余,但最近开始持续出现微博认证失败的状况. 摘录微博python SDK的错误提示如下所示: ERROR: ...
- openlayers常用操作
1.坐标转换 根据当前坐标系与目标坐标系进行转换ol.proj.transform(coordinate, source, destination); //coordinate:数组:source: ...
- java基础72 junit单元测试
1.junit要注意的细节 1.如果junit测试一个方法,在junit窗口上显示绿色代表测试成功:如果显示红条,则代表测试方法出现异常不通过. 2.如果点击方法名.包名.类名.工程名运行jun ...
- caffe+win7+vs2013 仅CPU环境安装
笔者对深度学习一直充满着好奇与兴趣,之前学校都是研究图像处理的特征点方式,机器学习使用也不多,别提深度学习了. 在看了李宏毅大佬的PPT后,有了初步的认识,虽然是渣渣电脑,也想自己跑几个深度模型. 说 ...
- C# 图片和二进制之间的转换
1> 图片转二进制 public byte[] GetPictureData(string imagepath){/**/////根据图片文件的路径使用文件流打开,并保存为byte[] Fil ...