Moving Tables
Problem DescriptionThe Famous ACM (Advanced computer Maker) company have rented a floor of a building whose shape was in the Following figure.
The floor has a rooms each of the side and South side along the corridor. Recently the company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables was big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out of the following plan:moving a table from a hostel to another the can is done within minutes. When moving a table from the class I to the Class J, the part of the corridor between the front of the class I and the front of the class J is Used. So, during each minutes, several moving between and rooms not sharing the same part of the corridor would be done Simult aneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
For each of the either, at the most one table would be a moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is-to-write a program to solve the manager ' s problem.
Inputthe input consists of T test cases. The number of test cases) (T is given in the first line of the input. Each test case begins with a line containing an integer N, 1<=n<=200, which represents the number of tables to move . Each of the following N lines contains-positive integers s and t, representing that a table was to move from the hostel numbe R S to the guest number T (each of the number appears at a once in the N lines). From the N+3-rd line, the remaining test cases is listed in the same manner as above.
Outputthe output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
Sample Output
102030
This topic should pay attention to 1--3 and 2--4 common section corridor. The first idea is to use the method of interval merging, but it is possible to move from 1 to 2, so that the method of interval merging is not applicable, so it has been WA. Then look at the data is not big, directly open an array f[205] storage number I of the corridor used several times. Also note that the point size of the input is not necessarily. The code is as follows:
#include <cstdio>int main () { int t,n,a,b; scanf ("%d", &t); while (t--) { int f[205]={0},sum=-1; scanf ("%d", &n); for (int i=0;i<n;i++) { scanf ("%d%d", &a,&b); int minx=a<b? (a+1)/2: (b+1)/2; int maxn=a<b? (b+1)/2: (a+1)/2; for (int i=minx;i<=maxn;i++) { f[i]++; if (f[i]>sum) sum=f[i]; } } printf ("%d\n", sum*10); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1050.Moving Tables "details and method Selection" "August 26"