793C: Mice problem
What I did wrong
-
since the given precision is 1e-6, the epsilon should be 1e-12, because of the base offraction arithmetic is (1e-6)^2
-
To calculate the range of valid time, i calculate the segment as a whole, instead of separating them into two dimesnions. This introduced additional float point calculation and introduced errors!!!
Idea
1. Mouses in ranges <=> each mouse is in range
2. Mouse in range <=> x is in x-axis range and y is in y-axis range. So we just need to search for a time range that satifies such condition.
3. Therefore, we just calculate the range it takes to stay in x-axis range and y-axis range, respectively, if there exists a common intersection, we know it is the answer, otherwise, it is impossible
4. When v < 0, we can just mirror the whole thing to the opposite sign => the result is still the same yet saves our coding
Reflections
Seems taht I keep having trouble with problems where we are searching for things that satifies both conditions at the same time. The main difficulty almost always seems that the two conditions interfere with each other.
Therefore, the key step is too process the two conditions in two steps, with each step handling one, without worrying about the interference of the other. Ideas include
1. search for first condition, when we are inside the first condition, we look for the second condition
2. Separate the construction, such that, each part handles one condition, and the final answer is a simple composition of parts, with proof that both parts can be reached at the same time
3. similar to 1, filter by the first conditon, and then filter by the second conditon, the result should should be an intersection of the two parts
As for this problem, we need to concisously transalte the orignal condition to two conditions and then handle the two in two steps. This way is easier to code, and in general often is the only way to solve the problem!