青蛙跳跳;

package com.code;

public class Test03_1 {
public int solution(int X, int Y, int D) {
int res = (Y-X)/D+((Y-X)%D==0?0:1);
return res;
} public static void main(String[] args) {
Test03_1 t03 = new Test03_1();
System.out.println(t03.solution(10, 85, 30)); }
} /** A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position
greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: class Solution { public int solution(int X, int Y, int D); } that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y. For example, given: X = 10
Y = 85
D = 30
the function should return 3, because the frog will be positioned as follows: after the first jump, at position 10 + 30 = 40
after the second jump, at position 10 + 30 + 30 = 70
after the third jump, at position 10 + 30 + 30 + 30 = 100
Assume that: X, Y and D are integers within the range [1..1,000,000,000];
X ≤ Y.
Complexity: expected worst-case time complexity is O(1);
expected worst-case space complexity is O(1).
*
*
*
*/

1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.的更多相关文章

  1. [geeksforgeeks] Count the number of occurrences in a sorted array

    Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...

  2. How to count the number of threads in a process on Linux

    If you want to see the number of threads per process in Linux environments, there are several ways t ...

  3. 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)

    Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...

  4. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  5. OpenCV count the number of connected camera 检测连接的摄像头的数量

    有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改: /** * Count current camera num ...

  6. fatal error C1003: error count exceeds number; stopping compilation解决方法

    [error]C1003: error count exceeds 100; stopping compilation ...winnt.h 在项目工程中添加#include<windows.h ...

  7. FB面经prepare: Count the number of Vector

    给一个超级大的排好序的vector [abbcccdddeeee]比如,要求返回[{,a}, {,b}, {,c}, {,d}, {,e}......]复杂度要优于O(N) 分析: 如果是binary ...

  8. js错误: Unexpected number in JSON at position 2792 value里面有双引号怎么解决

    源头  出现这个报错提示,大家从错误就可以看的出来,这就是json的错误,一般来说都是json格式出现了错误,本人遇到比较多的情况就是json字符串里面出现了一些会影响json格式的符号,这次出现这个 ...

  9. Time complexity--codility

    lesson 3: Time complexity exercise: Problem: You are given an integer n. Count the total of 1+2+...+ ...

随机推荐

  1. EasyUI系列学习(五)-Resizable(调整大小)

    一.创建组件 1.使用标签创建可变大小的窗口 <div id="rBox" class="easyui-resizable" style="wi ...

  2. servlet下的request&&response

    request的方法     *获取请求方式: request.getMethod();     * 获取ip地址的方法 request.getRemoteAddr();     * 获得用户清气的路 ...

  3. Firebug

    Firebug是网页浏览器火狐下的一款开发类插件,它集HTML查看和编辑.JavaScript控制台.网络状态监视器于一体,是开发JavaScript.CSS.HTML和Ajax的得力助手.F12打开 ...

  4. Position属性四个值:static、fixed、absolute和relative的区别

    1.static(静态定位):默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明). 2.relative(相对定位):生成相对 ...

  5. outlook 2016 接收发送无法及时收下邮件,如何更改接收时间?

    1. 单击“文件” > “选项” > “高级” > “发送和接收”,单击”发送/接收“ 2. 组“所有账户”的设置 > 打勾“安排自动发送/接收的时间间隔为(V)” 1 分钟 ...

  6. Farseer.net轻量级开源框架 中级篇:事务的使用

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: Where条件的终极使用 下一篇:Farseer.net轻量级开源框架 中级篇: ...

  7. Linux系统调用--getrusage函数详解

    Linux系统调用--getrusage函数详解 功能描述:     获得进程的相关资源信息.如:用户开销时间,系统开销时间,接收的信号量等等;   用法:    #include <sys/t ...

  8. bootstrap datatable 数据刷新问题

    在项目中,页面初始化的时候,通过通过向后台请求数据,页面初始化完之后,datatable是有数据的,当我点击页面的搜索按钮(按照时间过滤数据),datatable的数据要能重新刷新或者重载:这一点,我 ...

  9. SQlite数据库框架:LitePal

    常用的数据库框架Android的发展的速度是难以置信的,Android出来哪一年我还在小学上学很,还能很清楚的记得,那年一切,但是那个时候的我怎么可能也不会想到自己将来会要去做Android.Andr ...

  10. 【转载】eclipse设置护眼色详细教程

    先上一张效果图:     下面开始设置: 首先设置代码区的背景色: Window–>preference-->General-->Editors-->Test Editors ...