There are two thermometers and given five integers F1, B1, F2, B2 and T, where F1 and B1 are the Freezing point and Boiling Point of water on thermometer 1, and F2 and B2 are the Freezing point and Boiling Point of water on thermometer 2 respectively, and T is some temperature recorded on thermometer 1. The task is to find the temperature on the thermometer 2.
Input: F1 = 0, B1 = 10, F2 = 100, B2 = 200, T = 4
Input: F1 = 0, B1 = 100, F2 = 32, B2 = 212, T = 37
Approach: Consider the first thermometer to use U1 unit system and second thermometer using U2 unit system.
- The idea is to get the difference between the boiling and freezing point of water on each thermometer.
- The number of units between the freezing and boiling points of both thermometers shows the same temperature difference.
So, (B1 – F1) U1 == (B2 – F2) U2
By Unitary method, U1 = ( B2 – F2 ) / ( B1 – F1 ) U2
Relative value of U2 is T – F1 and U1 is T – F2
Hence, T = F2 + ( ( B2 – F2 ) / ( B1 – F1 ) ) * ( T – F1 )
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to convert temperature from degree Celsius to Kelvin
- Find temperature of missing days using given sum and average
- Count of days remaining for the next day with higher temperature
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Number of Integral Points between Two Points
- Prime points (Points that split a number into two primes)
- Minimum number of points to be removed to get remaining points on one side of axis
- Steps required to visit M points in order on a circular ring of N points
- Convert the number from Indian system to International system
- Convert the number from International system to Indian system
- Minimize cost to convert a given matrix to another by flipping columns and reordering rows
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Find X and Y intercepts of a line passing through the given points
- Find the equation of plane which passes through two points and parallel to a given axis
- Distance between end points of Hour and minute hand at given time
- Area of the largest rectangle formed by lines parallel to X and Y axis from given set of points
- Check if the given point lies inside given N points of a Convex Polygon
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.