plz help me any one as fast as u can
A thief Muthhooswamy planned to escape from **** jail. Muthhooswamy is basically a monkey man and he is able to jump across the wall. He practiced to cross a wall and he is able to jump 'X' meters, but because of slippery wall he fall 'Y' meters after each jump. To escape from jail he has to cross 'N' number of walls where height of each wall is given in an array. Write a program to find out the total number of jumps he will make to escape from the jail.
Input Specifications
Your program must read 4 arguments (climbUp, climbDown, noOfWalls,wallHeights[]) where
climbUp is the number of metres he can jump (1<=climbUp<=10^10)
climbDown is the number of metres he slides down (1<=climbDown<=10^5)
noOfWalls is the number of walls he needs to jump to escape (1<=noOfWalls<=10^5)
wallHeights[] is a single dimensional array where the height of each wall is provided, the ith element is (1<=i<=1000)
Output Specifications
Your program should return total number of jumps to the output variable output1 provided
Examples
Sample Input 1: 10:1:1:{10}
Here Muthooswamy can jump 10 metres height but slides down by 1 metre. He has 1 wall to jump and the height of the wall is 10 metres. Since he jumps 10 metres in the first attempt he cross the wall easily in the first attempt only.
Sample Output 1: 1
Sample Input 2: 5:1:2:{9,10}
Here Muthooswamy can jump 5 metres height but slides down by 1 metre. He has 2 walls to jump and the height of each wall is 9 and 10 metres respectively.
While crossing the first wall, Muthooswamy takes 2 attempts because during the first attempt he jumps 5 metres but slides down by 1 metre since he didn't cross the wall. In the next attempt he jumps 5 more metres from that position and this time he doesn't slide because he crossed the wall in this attempt because 4+5=9 and 9 metres is the actual height of the wall.
Similarly while crossing the second wall, Muthooswamy takes 3 attempts because during his second attempt on this wall, he slides down by 1 metre since 4+5=9 and the height of the wall is 10 metres. During his third attempt, Muthooswamy was able to escape from ***
Sample Output 2: 5
View Answers
October 8, 2011 at 3:27 PM
import java.io.*;
import java.util.Arrays;
public class UserMainCode
{
//Assume following return types while writing the code for this question.
public static int output1;
public static void GetJumpCount(int climbUp,int climbDown,int noOfWalls,int[] wallHeights)
{
while(noOfWalls>0){
output1 = jumpAmount(output1, climbUp, wallHeights[--noOfWalls], climbDown);
}
}
private static int jumpAmount(int totalJump, int climbUp, int hight, int climbDown){
if( hight <= climbUp){
return ++totalJump;
}
else{
hight = hight - (climbUp - climbDown);
return jumpAmount(++totalJump, climbUp, hight, climbDown);
}
}
public static void main(String[] args) {
int a[] = new int[]{10,20};
GetJumpCount(10,1,2,a);
System.out.println(output1);
}
}
October 8, 2011 at 3:28 PM
public class UserMainCode
{
public static int output1;
public static void GetJumpCount(int climbUp,int climbDown,int noOfWalls,int[] wallHeights)
{
while(noOfWalls>0)
output1 = jumpAmount(climbUp, wallHeights[--noOfWalls], (climbUp - climbDown));
}
private static int jumpAmount(int climbUp, int hight, int oneJump){
if( hight <= climbUp)
return ++output1;
else{
++output1;
return jumpAmount(climbUp, (hight-oneJump), oneJump);
}
}
public static void main(String[] args) {
int a[] = new int[]{10,20};
GetJumpCount(10,1,2,a);
System.out.println(output1);
}
}
October 8, 2011 at 3:28 PM
public class UserMainCode
{
public static int output1;
public static void GetJumpCount(int climbUp,int climbDown,int noOfWalls,int[] wallHeights)
{
while(noOfWalls>0)
output1 = jumpAmount(climbUp, wallHeights[--noOfWalls], (climbUp - climbDown));
}
private static int jumpAmount(int climbUp, int hight, int oneJump){
if( hight <= climbUp)
return ++output1;
else{
++output1;
return jumpAmount(climbUp, (hight-oneJump), oneJump);
}
}
public static void main(String[] args) {
int a[] = new int[]{10,20};
GetJumpCount(10,1,2,a);
System.out.println(output1);
}
}
Ads
Related Tutorials/Questions & Answers:
plz help me any one as fast as u can
plz help me any one as
fast as
u can A thief Muthhooswamy planned... is the number of metres he
can jump (1<=climbUp<=10^10)
climbDown...
Sample Input 1: 10:1:1:{10}
Here Muthooswamy
can jump 10 metres height
Advertisements
Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone
Can any one please
help me in this ,,,,,,, need java code for this ,,,,please anyone The Airport Valet Parking Company (AVP) is a company which provides a convenient medium cost parking solution to users of a local airport. Key
plz help me for this question
plz help me for this question Apply simplex procedure to solve the L.P.P. maximize z = 3x1 + 4x2 subject to 5x1 + 4x2 â?¤ 200; 3x1 + 5x2 â?¤ 150; 5x1 + 4x2 â?¥ 100; 8x1 + 4x2 â?â?¥ 80, x1 â?¥ 0, x2 â?¥ 0
Plz Help Me
Plz Help Me Write a program for traffic light tool to manage time giving between Main-Street and sub-Street. firstly, give green light for 40... traffic light on the frame. We have used java swing. It may
help you.
import
plz help me - Java Beginners
plz help me deepak hw
can i create a data grid in jsp and also how
can i connect to the data base
plz help me to create data grid in jsp use html tables with borders.
to connect to data base use scriptlets.
ex
Intranet Website creation - plz help me
Intranet Website creation -
plz help me hi..
I have assign with the intranet website creation work..right from scratch to end..And honestly I know nothing about it.My domain is totally different ..
can anybody pls
help me
interview question plz help me and thers
interview question
plz help me and thers A college is good... "M.Tech" is
one of the courses offered, it must also offer "B.Tech" and "MCA" courses.
5.If "MBBS" is
one of the courses, it must not offer a "B.Tech" Course
can any one explain this
can any one explain this class Clidder {
private final void flipper() {
System.out.println("Clidder");
}
}
public class Ex3 extends Clidder {
public final void flipper() {
System.out.println
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code. I want php code for bellow OUTPUT.
output is just example but it must be letters only.
abc
bcd
efg
jku
rgt
azs
hje
qqc
wws
adt
help me plz befor 27 februry
help me plz befor 27 februry what is rung with this ??
help me plzzzz
import java.util.Scanner;
public class Initials
{
public static void main (String [] args)
{
String firstname,lastname
Can someone help me with this?
Can someone
help me with this? I have this project and i dont know how to do it.
Can someone
help me? please?
Write a java class named "PAMA..., Multiply, Divide)
Help me please! Thanks in advance!
import
plz Help me find the correct programs answers
plz Help me find the correct programs answers
Create a washing... INDICA" and "TATA NANO" respectively.
Plz mail
me your answers... to the program so as to accept
any type of numeric values and returns the results
population problem plz help me befor 16 March 2011 !!
population problem
plz help me befor 16 March 2011 !! the
Q is :
How
can i count how many years it will take for the population of a town to go over 30.000 .. consider that it Increases 10% every year ??
And this is my code &
Can you help me with applet?
Can you
help me with applet? I'm very new to applet, and i'm weak in graphic design part. How
can i add the graphic in my test project?
Can you
help me with this:
import java.io.*;
import java.util.*;
import javax.swing.
Can anybody help me with this simple MySql code
cad 2013-03-16 18:26:31
can any one help me with the query because i want to select al of them but it should select for
me only 1 duplicate countryid...
Can anybody
help me with this simple MySql code select c.countryid
Plz Help
Plz Help Hello Guys!!
Plz.
Help
I need to write a program to display the astrological sign based on your birthday for example
If we enter the date of birth in the following format from console--13/08/1990
it should give you