http://codeforces.net/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 :)
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
http://codeforces.net/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 :)
Name |
---|
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