Maximum Value of a Fraction Table
InterviewTime limit1sMemory limit128 MB
Given a 2x2 grid of positive integers, find how many 90-degree clockwise rotations (0-3) maximize A/C+B/D, choosing the smallest such count on ties.
- Level
Easy2 of 10
- Topics
- Brute force, Implementation, Simulation
- Solved
- No attempts yet
Problem
Sanggeun is not good at addition or division. Jeongin gave him a 2*2 table made of positive integers A, B, C, and D.
The value of the table is defined as A/C + B/D.
Sanggeun wants to know how many times he should rotate the table clockwise by 90 degrees so that the value becomes as large as possible. The original table is considered to have been rotated 0 times.
After 1 clockwise rotation, the table becomes:
After 2 clockwise rotations, the table becomes:
Given A, B, C, and D, write a program that prints the number of rotations that maximizes the table value.
Input
The first line contains A and B separated by a space. The second line contains C and D separated by a space. Every number is a positive integer at most 100.
Output
Print how many times the table should be rotated to maximize its value. If more than one rotation count gives the maximum value, print the smallest such count.