1814
A_Coins
Explanation
- First, check if n is even. If it is, you can always represent n using coins of denomination
2 (2*x = n, and y = 0)
. - If
n
is odd, then the only way to representn
is by using an odd number ofk
coins and an even number of 2 coins (since the sum of an odd number of odd integers and an even number of even integers is odd). In this case, check ifn >= k
andk
is odd. If so, it's possible to represent n using these coins.
If n is even, then you can always represent n using only coins of denomination 2. If n is odd, it checks if n is greater than or equal to k and if k is odd. If this condition is satisfied, you can represent n using the given coins. Otherwise, it's not possible to represent n using the coins.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
B_Long_Legs
Explanation
- Iterate through possible leg lengths (
m
) from 1 to a large number (e.g.,10^5
). - For each leg length
m
, calculate the number of horizontal jumps (jumps_a
) and vertical jumps (jumps_b
) the robot needs to reach cellsa
andb
, respectively. - The total moves required for each leg length
m
is the sum ofm
(number of times the robot increases its leg length),jumps_a
, andjumps_b
. - Keep track of the minimum moves among all leg lengths.
Iterates through possible leg lengths (m) and calculates the number of horizontal jumps (jumps_a) and vertical jumps (jumps_b) required to reach the target cell (a,b) for each leg length. The minimum number of moves for the robot is the sum of the leg length increases and the number of horizontal and vertical jumps. By iterating through leg lengths and keeping track of the minimum moves, the solution finds the optimal leg length and the minimum number of moves required to reach the target cell.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
C_Search_in_Parallel
Explanation
You have n boxes with balls of different colors and two robots to retrieve balls for you. You need to assign the boxes to two lists (a and b), one for each robot. When you request a ball of color x, the robots search the boxes in their list one by one. The first robot takes s1 seconds to analyze a box, and the second robot takes s2 seconds. You have to assign the boxes to the lists in such a way that the total search time for all requests is minimized.
- Sort the boxes in decreasing order of the number of requests for their corresponding color.
- Iterate through the sorted list of boxes.
- Assign each box to the robot that will minimize the total search time.
- Print the lists a and b.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|