rsazid99's blog

By rsazid99, history, 8 years ago, In English

http://mirror.codeforces.com/contest/724/problem/C

I have been trying to solve this problem , but i don't have any ideas. can anyone help me ?? Thanks in Advance :)

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Note that the ray trajectory is a straight line with slope either +1 or -1 (depending on reflection). Therefore these trajectories are: y = x + c and y = -x + k. Now for each point determine the value of the constants c and k, and store them mapped to {constant, slope}. Once this is done, simulate the situation given in the problem.

When the ray started at (0,0), determine its point of contact with the box walls. Now determine the slope after reflection ( -1 <-> +1 ) and also the direction (let's say upward/downward). Using the slope and point of contact, determine the value of the constant 'c' (y = mx+c) such that point of contact lies on the line. Now use this constant and slope to iterate through all points (we stored earlier) and calculate their answers (using their x/y coordinates, note that it takes 1 sec go 1 m in x/y dir). Use the direction and pt of contact to get the next point of contact. Repeat this until you cover all points or you reach a corner.

Since n, m < 10^5. We will have at max n+m lines with slope +1 and n+m for -1. Therefore this simulation can be done within the time limit.

Code