青蛙跳跳;

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. Java编程思想读书笔记_第7章

    final关键字类似const: import java.util.*; public class FinalData { static Random rand = new Random(47); f ...

  2. Crash reporter

    A crash reporter is a software application whose function is to identify report crash details and to ...

  3. Linux 报错 ifconfig command not found

    1.Linux 中输入ifconfig命令报错:ifconfig command not found 有可能是没有安装ifconfig,如果没有,安装上去 2.查看是不是缺少了ifconfig,它是在 ...

  4. 事件的节流(throttle)与防抖(debounce)

    事件的节流(throttle)与防抖(debounce) 有些浏览器事件可以在短时间内快速触发多次,比如调整窗口大小或向下滚动页面.例如,监听页面窗口滚动事件,并且用户持续快速地向下滚动页面,那么滚动 ...

  5. pl/sql编程语言

    –pl/sql编程语言–pl/sql编程语言是对sql语言的扩展,是的sql语言具有过程化编程的特性–pl/sql编程语言比一般的过程化编程语言,更加灵活高效–pl/sql编程语言主要用来编写存储过程 ...

  6. css去掉div的滚动条

    懒得讲原理了,直接贴代码: css部分: .slide-box { margin-top: 200px; display: -webkit-box; overflow-x: scroll; overf ...

  7. 山建校赛B题公式证明

    原题 证明

  8. MySQL各种版本的下载方式

    1.在百度上搜“MySQL”,进入官网 原文地址:https://blog.csdn.net/mieleizhi0522/article/details/79109195

  9. linux free命令-显示内存的使用情况

    更多Linux 性能监测与优化 关注 Linux命令大全 free命令可以显示当前系统未使用的和已使用的内存数目,还可以显示被内核使用的内存缓冲区. 语法 free(选项) 选项 -b:以Byte为单 ...

  10. Django 命令行调用模版渲染

    首先我们需要进入 Django 的 shell python manage.py shell 渲染模版中的 name from django.template import Context,Templ ...