Algorithm
problem Link : https://www.codechef.com/problems/BULLET
Problem
Mario's bullet moves at pixels per frame. He wishes to shoot a goomba standing pixels away from him. The goomba does not move.
Find the minimum time (in seconds) after which Mario should shoot the bullet, such that it hits the goomba after at least seconds from now.
Input Format
- The first line of input will contain an integer , the number of test cases. Then the test cases follow.
- Each test case consists of a single line of input, containing three space-separated integers and .
Output Format
For each test case, output in a single line the minimum time (in seconds) after which Mario should shoot the bullet, such that it hits the goomba after at least seconds from now.
Constraints
- divides
Sample 1:
3 3 3 5 2 4 1 3 12 8
4 0 4
Explanation:
Test case : The speed of the bullet is pixels per frame and the goomba is pixels away from Mario. Thus, it would take second for the bullet to reach the goomba. Mario wants the bullet to reach goomba after at least seconds. So, he should fire the bullet after seconds.
Test case : The speed of the bullet is pixels per frame and the goomba is pixels away from Mario. Thus, it would take seconds for the bullet to reach the goomba. Mario wants the bullet to reach the goomba after at least second. So, he should fire the bullet after seconds. Note that, this is the minimum time after which he can shoot a bullet.
Test case : The speed of the bullet is pixels per frame and the goomba is pixels away from Mario. Thus, it would take seconds for the bullet to reach the goomba. Mario wants the bullet to reach goomba after at least seconds. So, he should fire the bullet after seconds.
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include<stdio.h>
int main()
{
int t,x,y,z,s;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&x,&y,&z);
s=z-(y/x);
if(s<=0) printf("0\n");
else printf("%d\n",s>;
}
}
Copy The Code &
Try With Live Editor
Input
3 3 5
2 4 1
3 12 8
Output
0
4
Demonstration
CodeChef solution BULLET - Mario and Bullet Codechef solution in C,C++