HDU 1050 moving tables & nyoj 220 push table

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.