Reprinted please indicate the source: Thank youHttp://user.qzone.qq.com/289065406/blog/1299062100
Tip: use the room number to separate the corridor. A counter is set for each "sub-corridor". Each time a + 1 is passed, the counter is sorted quickly. The maximum number of times x10 is the answer.
This question is a bit greedy at first, because it may be very stupid and inefficient to calculate the intersection point (critical point) of the input moving range, in addition, we need to consider a bunch of possible situations. I have done this using the stack in this way and listed all possible examples. The results are consistent but there is no limit to wa .... So let the public: Do not go astray...
// Memory time // 232 K 0 Ms # include <iostream> # include <algorithm> using namespace STD; int main (void) {int room [401]; int test, move_time, I, j, temp; int from [200], to [200]; CIN> test; For (j = 0; j <test; j ++) {memset (room, 0, sizeof (room); // note that initialization is required for each test, instead of initializing CIN> move_time; for (I = 0; I <move_time; I ++) {CIN> from [I]> to [I]; If (from [I]> to [I]) {temp = from [I]; from [I] = to [I]; To [I] = temp;} If (from [I] % 2! = 0) from [I] ++; If (to [I] % 2! = 0) to [I] ++; For (temp = from [I]; temp <= to [I]; temp + = 2) {room [temp] ++ ;}} sort (room, room + 401); cout <room [400] x 10 <Endl ;}return 0 ;}