uva846:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=787

题意:给你两个数x,y,x<=y,现在让你从x走向y,开始的第一次和最后一次,只能够移动一步,之后每一次走的步数和上次走的步数之和之差不超过1.问你到达y最小需要多少步。

题解:从x,y同时开始走,每次步数加一,如果走到两者刚好相遇则停止,如果剩余的距离不超过当前的步数,也可以停止,因为这剩余的距离可以在之前的某个时间段走完,相当于在之前走了一个水平的阶段。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x,y;
int main(){
int cas;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&x,&y);
int counts=,step=;
while(){
if(x>=y){
printf("%d\n",*counts);
break;
}
if(y-x<=step){
printf("%d\n",*counts+);
break;
}
else{
x+=step;
y-=step;
counts++;
step++;
}
}
}
}

Steps的更多相关文章

  1. animation-timing-function: steps() 详解

    在应用 CSS3 渐变/动画时,有个控制时间的属性 <animation-timing-function> .它的取值中除了常用到的 贝萨尔曲线以外,还有个让人比较困惑的 steps()  ...

  2. CSS3 Animation 帧动画 steps()

    @keyframes fn{ 0%{} 100%{} } CSS3的Animation有八个属性 animation-name :动画名 fn animation-duration:时间 1s ani ...

  3. SAML 2.0 setup steps, 效果图

    Steps of setting up SAML SSO. 效果图 # Registry a Identity Provider services in:(Might need purchase) I ...

  4. 【译】css动画里的steps()用法详解

    原文地址:http://designmodo.com/steps-c... 原文作者:Joni Trythall 我想你在css 动画里使用steps()会和我一样有很多困惑.一开始我不清楚怎样使用它 ...

  5. css3动画中的steps值详解

    css3的动画的animation-timing-function属性定义了动画的速度曲线,一般的速度曲线大家都知道,什么ease,linear,ease-in,ease-out,还有自定义贝塞尔曲线 ...

  6. steps animation

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. sdutoj 2623 The number of steps

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...

  8. SAP NWBC for HTML and Desktop configuration steps[From sdn]

    Summary :- This dcoumnenst conatin the information about requirement , hardware , configuration step ...

  9. 【转载】7 Steps for Calculating the Largest Lyapunov Exponent of Continuous Systems

    原文地址:http://sprott.physics.wisc.edu/chaos/lyapexp.htm The usual test for chaos is calculation of the ...

  10. BSGS算法_Baby steps giant steps算法(无扩展)详解

    Baby Steps-Varsity Giant Step-Astronauts(May'n・椎名慶治) 阅读时可以听听这两首歌,加深对这个算法的理解.(Baby steps少女时代翻唱过,这个原唱反 ...

随机推荐

  1. 理解Android的startservice和bindservice(转)

    一.首先,让我们确认下什么是service? service就是android系统中的服务,它有这么几个特点:它无法与用户直接进行交互.它必须由用户或者其他程序显式的启动.它的优先级比较高,它比处于前 ...

  2. What is therelationship between @EJB and ejb-ref/ejb-local-ref?

    http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html What is therelationship between @EJB and ejb-ref/ ...

  3. ie11只能用管理员身份打开解决办法

    解决IE11只能用管理员身份运行的问题 不知道大家有没有遇到这种情况,在毫不知情的情况下 IE11 突然打不开了,必须要用管理员身份运行才可以打开,而且重置浏览器这个方法也不奏效. 今天本人也遇到了, ...

  4. QT unit test code coverage

    准备环境: qt-creator5.2.1 , gcov(gcc 默认安装),lcov(gcov 的图形化显示界面),qt_testlib 各环境介绍: 1.gcov   gcov 是一个可用于C/C ...

  5. 关于 Java Collections API 您不知道的 5 件事--转

    第 1 部分 http://www.ibm.com/developerworks/cn/java/j-5things2.html 对于很多 Java 开发人员来说,Java Collections A ...

  6. 2015移动安全挑战赛(阿里&看雪主办)第一题分析

    今天在网上看到了阿里移动安全比赛的第一次,并且说难度不大,便拿来看了看. 主体就是找出一个密码输进去,然后看正误. 这个题是纯Java层的一个题,也没用进行什么保护.可以直接反编译. 登陆Button ...

  7. C++ | 调试 · 从汇编代码看i++和++i的区别

    以int类型为例 C++编译器为++i生成的代码是 013E1375 mov eax,dword ptr [i] 013E1378 add eax, 013E137B mov dword ptr [i ...

  8. COGS 渡轮问题 (LIS规定字典序输出方案数)

    /* 下标字典序最小 */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 1 ...

  9. Jquery~$when_done_then的用法

    对于$.ajax请求来说,如果层级比较多,程序看起来会比较乱,而为了解决这种问题,才有了$when...done...fail...then的封装,它将$.ajax这嵌套结构转成了顺序平行的结果,向下 ...

  10. Wpf TextChanged事件导致死循环,事件触发循环问题

    1.实例: 说明:当TextBox控件的Text内容发生变化时,TextChanged事件触发,并且会立即同步执行. 基于这个特点,设置一个全局变量标识,ChangeTxtB,如果是正在修改txtB的 ...