Relativity (RELATIVE) Solution — Codechef July Long Challenge
In Chefland, the speed of light is c m/s, and acceleration due to gravity is g m/s2.
Find the smallest height (in meters) from which Chef should jump such that during his journey down only under the effect of gravity and independent of any air resistance, he achieves the speed of light and verifies Einstein’s theory of special relativity.
Assume he jumps at zero velocity and at any time, his velocity (v) and depth of descent (H) are related as
- The first line contains an integer T, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, two integers g, c.
For each test case, output in a single line the answer to the problem. We can show that under the constraints, the answer is an integer.
- 2⋅g divides c2.
Subtask #1 (100 points): Original constraints
Test Case 1: For Chef to achieve the speed of light, the minimum height required is c2/2g = 1400⋅1400/14 = 140000 meters.
Test Case 3: For Chef to achieve the speed of light, the minimum height required is c2/2g = 1000⋅1000/20 = 50000 meters.
The code has been implemented in Java
/* package codechef; // don't place package name! */import java.util.*;
import java.io.*;/* Name of the class has to be "Main" only if the class is public. */
public static void main (String args) throws java.lang.Exception
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int g = sc.nextInt();
int v = sc.nextInt();
Hope you would have liked the article. Please give 50 claps to this article and follow me for more future programming related blogs.
Contest Page | CodeChef
CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming…
(Video Editorial Link For Better Explanation)