A. Robot Cleaner
Solution:
Just simulate the behavior of the robot according to the requirements of the problem.
Code:
Java
C++
B. Game on Ranges
Solution:
First, use a map<int, set> to record all the ranges, where L is the key of the map, and R is recorded in the set. Then for each range, we enumerate D to see if [L, D-1] and [D+1, R] have appeared.
Code:
Java
C++
C. Balanced Stone Heaps
Solution:
Binary search final result.
Then check from the n-th heap to the 3rd heap in turn.
For the i-th heap currently under inspection, we divide the stones into two categories: 1. Originally belonging to h[i], this category can be assigned to i-1 and i-2; 2. The stones that come from i+1 and i+ 2, I record as buff[i].
If the sum of h[i]+buff[i] is not enough to satisfy the result, then the result must be too large. Otherwise we can divide h[i] into i-1 and i-2 as much as possible.
Code:
Java
C++
Question D is pure mathematics, which is a pure infinite series summation. It's too boring. After all, it's almost Chinese new year, so I'm too lazy to do it.