HDOJ_1045Moving Tables(动表)

来源:互联网 发布:上海软件培训班多少钱 编辑:程序博客网 时间:2024/05/11 12:23

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. 

                                                                                    
The floor has 200 rooms each on the north 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 are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving. 

                                                                        

For each room, at most one table will be either 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.


Input

The 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 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.

Output

The output should contain the minimum time in minutes to complete the moving, one per line.


Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
 

Sample Output
102030

(百度翻译)

     著名的ACM(高级电脑制造商)公司租了一栋楼,其形状如下。             地板有200个房间在走廊的北侧和南侧。最近公司制定了一项改革计划。改革包括在房间之间移动许多桌子。因为走廊狭窄,桌子都很大,只有一张桌子可以穿过走廊。需要一些计划,使移动效率。经理想出了以下的计划:把桌子从房间移到另一个房间可以在10分钟内完成。当我把房间从房间移到J房间时,房间前部和房间前部之间的走廊的一部分被使用。因此,在每10分钟,两个房间之间的移动不共享走廊的同一部分将同时完成。为了说明清楚,经理说明了可能的情况和不可能的情况下,同时移动。             对于每个房间,最多一个表将被移动或移出。现在,经理寻找一种方法来最小化移动所有表的时间。你的工作是写一个程序来解决经理的问题。 


输入:

由t测试用例。测试用例的数量)(t在输入的第一行中给出)。每个测试用例以一个包含n个整数的1行开始,它代表了要移动的表的个数。每个下面的N行包含两个正整数S和t,表示一个表是从房间编号S移动到房间编号t(每个房间号在N行中最多出现一次)。从N +三线,其余的测试用例是以同样的方式列为以上。 


输出:

输出应该包含最小的时间在几分钟内完成移动,每行。


实际上就找最大重叠的区间是多少,重叠次数每多一个就要多十分钟,具体代码如下:

#include<stdio.h>int main(){int i,j,T,t1,t2,n,m1,m2;scanf("%d",&T);while(T--){int time=0; int a[625]={0};scanf("%d",&n);while(n--){scanf("%d%d",&m1,&m2);t2=m1>m2?m1:m2; //可以从大的房间号移动到小的房间号t1=m1<m2?m1:m2;for(i=(t1+1)/2;i<=(t2+1)/2;i++)//(t+1)/2主要是对房间过道走廊进行讨论a[i]++;                        //用数组进行模拟过道走廊}for(i=1;i<=400;i++)if(a[i]>time)  time=a[i];          //找出最大重叠区间printf("%d\n",time*10);}return 0;}