Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1050
This problem is caused by the choice of non-Intersecting intervals. It is important to model the actual problem as a basic problem. For example, both Room 3 and Room 4 should "add one, divide two" and convert it to 2, note that the start and end values of the two inputs are not necessarily arranged in order of size. For example, you need to change them from room10 to room1.
Sort by Start Time in ascending order and traverse from I = 0. First, locate the unvisit range. If yes, num + = 10 (indicatesI can be arranged at this venue, and then I will start to look for a range that can be moved at the same time with this range.), Retain the last at the end of the I-th interval, and then nest traversal. j ranges from I + 1 to n-1. If the start of the J-th interval is greater than last, in this case, you can use the J-th interval to change the last value and mark the J-th interval as visit.
# Include <iostream> # include <cstring> # include <algorithm> using namespace STD; struct y {int from; int to; int visit;} Move [210]; bool CMP (Y p, y q) {return p. from <q. from;} int main () {int t; CIN> T; while (t --) {int N; CIN> N; int A, B; memset (move, 0, sizeof (MOVE); For (INT I = 0; I <n; I ++) {CIN> A> B; move [I]. from = (a + 1)/2; move [I]. to = (B + 1)/2; If (move [I]. from> move [I]. to) Swap (move [I]. from, move [I]. to);} Sort (move, move + N, CMP); int num = 0; For (INT I = 0; I <n; I ++) {If (move [I]. visit = 0) {num + = 10; // if no visit exists, add 10 minutes int last = move [I]. to; For (Int J = I + 1; j <n; j ++) {If (move [J]. visit = 0 & move [J]. from> last) {move [J]. visit = 1; last = move [J]. to ;}}}cout <num <Endl ;}return 0 ;}