Computer Science, asked by meghashreejm, 1 year ago

An activist, of a banned organisation, plans to escape from Bhopal jail. The activist is basically a monkey man and is able to jump across the wall. He practises to cross a wall. He is able to jump 'X' meters, but because of the slippery wall he falls '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 has to make, to escape from the Bhopal jail.
Input Format
Your function will take three arguments:
An integer depicting X
An integer depicting Y
An array of N integers having the height of each wall
Constraints
1<= X <=109
1<= Y <=105
Output Format
Your program should return total number of jumps required to escape.
Sample Test Cases
Test case 1
Sample Input
10
1
1
10
Sample Output
1
Explanation
Here, the activist can jump 10 meters high, but slides down by 1 meter. He has 1 wall to jump and the height of the wall is 10 meters. Since he jumps 10 meters in the first attempt he cross the wall easily in the first attempt only.
Test case 2
Sample Input
5
1
2
9
10
Sample Output
5
Explanation
Here, the activist can jump 5 meters high but slides down by 1 meters. He has 2 walls to jump and the walls are 9 and 10 meters high respectively.
While crossing the first wall, the activist takes 2 attempts because during the first attempt he jumps 5 meters but slides down by 1 meters since he didn't cross the wall. In the next attempt he jumps 5 more meters from that position and this time he doesn't slide because he crossed the wall in this attempt because 4+5=9 and 9 meters is the actual height of the wall.
Similarly, while crossing the second wall, the activist takes 3 attempts because during his second attempt on this wall, he slides down by 1 meters since 4+5=9 and the height of the wall is 10 meters. During his third attempt, Activist was able to escape from Bhopal Jail.

Answers

Answered by manishyouth
3
#include<stdio.h>#include<conio.h>int main(){ int jump,slide,f_jump,n_wall,i; int result=0; int n; printf("Enter the number of wall"); scanf("%d",&n_wall); int arr[n_wall]; printf("Enter the size of wall"); for(i=0;i<n_wall;i++) { scanf("%d",&arr[i]); } printf("Enter the capacity of jump"); scanf("%d",&jump); printf("Enter the sliding distance"); scanf("%d",&slide); f_jump=jump-slide; for(i=0;i<n_wall;i++) { if(arr[i]<=jump)
{ result=result+1;  } else if(arr[i]%f_jump==0 && arr[i]>jump) { n= arr[i]/f_jump; result= result+n; } else if(arr[i]%f_jump!=0 && arr[i]>jump) { n= arr[i]/f_jump; result= result+n+1; } } printf("Number of jump to escape the bhopal jail is %d", result);}

Try it.
this is my effort to solve this qn.
if u feel any confusion comment please.
happy to help.

Similar questions