http://codeforces.me/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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
http://codeforces.me/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