以下為我的解題想法:
define the directions of light:
0 right
1 left
2 up
3 down
reflections:
/:
0 > 2
1 > 3
2 > 0
3 > 1
f(x) = (x + 2) % 4
\:
0 > 3
1 > 2
2 > 1
3 > 0
g(x) = 3 - x
------------------------------------------------------------------------------------------------
psuedo::start
mirrors sort by x -> X
mirrors sort by y -> Y
x_of_light = 0
y_of_light = 0
dir = 0
if (dir = 0) {
new_mirror = upper_bound(Y[y_of_light], x_of_light)
}
if (dir = 1) {
new_mirror = lower_bound(Y[y_of_light], x_of_light) - 1
}
if (dir = 2) {
new_mirror = upper_bound(X[x_of_light], y_of_light)
}
if (dir = 3) {
new_mirror = lower_bound(X[x_of_light], y_of_light) - 1
}
new_x = mirror.x
new_y = mirror.y
new_dir = f(dir) if new_mirror.dir = 0 else g(dir)
source: judges/i401 3 雷射測試.cpp at main · 20060705Sean/judges (github.com)