51nod 1615 跳跃的杰克
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1615
题意:

思路:
一开始是觉得一旦超过了终点,中间某个地方往相反地方跳就可以了,后来发现只有超过距离是偶数时才行,奇数是不行的。那么奇数怎么办呢,继续往前跳,直到间距为偶数即可。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; ll x; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%lld",&x))
{
if(x<) x=-x;
ll sum = ;
int i=;
for(;;i++)
{
sum+=i;
if(sum>=x) break;
}
if(sum>x && ((sum-x)&))
{
while((sum-x)&) sum+=++i;
}
cout<<i<<endl;
}
return ;
}
51nod 1615 跳跃的杰克的更多相关文章
- 51nod百度之星2016练习赛
今天看了看51nod发现有这样一个练习赛,就做了做.因为实力太弱想不出E题,各位神犇勿D. (5.26UPD:E题想粗来了) A 区间交 不难发现若干线段[li,ri]的交就是[max(li),min ...
- 51nod 最近刷题 简要题解
51nod 1564 由于数据是随机的,可以证明,对于每一个数,向左或右找比它小的数,长度是logn级别的 考虑枚举最大值 注意,对于每一个最大值,如果直接用2个循环枚举左右端点的话,理论是lognl ...
- 51NOD 1709:复杂度分析——题解
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1709 (我什么时候看到二进制贡献才能条件反射想到按位处理贡献呢……) 参 ...
- 跳跃的舞者,舞蹈链(Dancing Links)算法——求解精确覆盖问题
精确覆盖问题的定义:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 例如:如下的矩阵 就包含了这样一个集合(第1.4.5行) 如何利用给定的矩阵求出相应的行的集合 ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- [LeetCode] Jump Game II 跳跃游戏之二
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
随机推荐
- golang学习笔记10 beego api 用jwt验证auth2 token 获取解码信息
golang学习笔记10 beego api 用jwt验证auth2 token 获取解码信息 Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放 ...
- java获取前一天时间SimpleDateFormat,java判断某个时间段
java获取前一天时间SimpleDateFormat SimpleDateFormat predf = new SimpleDateFormat("yyyy-MM-dd"); D ...
- PNG文件格式详解
源文件地址:https://blog.mythsman.com/2015/12/08/1/ 最近在看隐写术的时候经常需要研究图片文件的二进制文档格式,那么这就很有必要了解我们的图片文件究竟是如何保存的 ...
- How to use Nissan consult 3 plus to check, make key and program?
How to use Nissan consult 3 plus to test Nissan? Firstly: get one particular Nissan consult 3 plus. ...
- GM Bosch Vetronix HP Tech 2 with CANDI
Being I have owned some of these units. Can offer some advice… GM Tech 1, GM Tech 1a. Early and latt ...
- Django框架----跨表查询及添加记录
一:创建表 书籍模型: 书籍有书名和出版日期,一本书可能会有多个作者,一个作者也可以写多本书,所以作者和书籍的关系就是多对多的关联关系(many-to-many); 一本书只应该由一个出版商出 ...
- mybatis 3.2.*打印sql结果集
虽然可以写个interceptor记录下,但是总归没有log4j来的自然.一段时间不查问题,总是要忘了,记录下: 在mybatis 3.2.*中,可以在log4j中如下配置: log4j.logger ...
- .net下安装 ZooKeeper.Net
PM> Install-Package ZooKeeper.Net正在尝试解析依赖项“log4net (≥ 1.2.10)”.正在安装“log4net 1.2.10”.已成功安装“log4net ...
- 【题解】Luogu P3901 数列找不同
我博客中对莫队的详细介绍 原题传送门 不错的莫队练手题 块数就直接取sqrt(n) 对所有询问进行排序 排序第一关键词:l所在第几块,第二关键词:r的位置 考虑Ai不大,暴力开数组 add时如果加之后 ...
- 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows
原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...