HDU1050 Moving Tables

原创 2015年11月18日 13:44:43

Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25394    Accepted Submission(s): 8408


Problem Description
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
10 20 30
 

题目大意:就是著名的ACM公司在一栋写字楼租了一层,然后这一层房间的构造如题目所给的图示,分南北两边,每一边都有200个房间,中间有一条过道;现在要在移动一些房间里面的办公桌,办公桌很大,但是走廊过道很窄每次只能通过一张桌子。每一次将办公桌从 i 房间移动到 j 房间都需要10分钟,那么公司想要在最短的时间内将这些桌子移动到房间,并且只要移动时没有公共过道的部分都可以同时进行;总经理给出了能够移动桌子的情况和不能移动桌子的情况;如下:


也就是说 将桌子从30号房间到50号房间移动的时候可以同时将60号的桌子移动到90号,因为它们没有占用共同的过道;

而当将桌子从20号房间移动到40号房间的时候就不能同时将31号房间的桌子移动到80号房间了  因为他们中间有共同的过道,当第一张桌子移动的时候走廊上个是没有空间移动其他桌子的了。


输入第一行有个T表示接下来有T次的测试数据。然后接下来有N,表示有N张桌子需要移动;接下里有N行,每一行有一组 i 和 j 表示从i 号房间移动到 j 号房间。


省题:由题意可知,我们要求的是最少需要花费多少时间移动N张桌子。每次移动的时候如果存在走廊被占用的时候就不能同时移动,如果没有同时被占用就可以同时移动这几张桌子。那么我们可以把它理解成每次移动的时候在 i 到 j 的房间过道上画线,然后找到从复最多的次数的房间乘以移动一次桌子所需要花费的时间就是我们移动N张桌子所需要花费的最少时间;


思路:我们可以每次给数组加一来模拟画线的过程,所以定义一个整型数组count[406],每次有桌子从 i 号房间移动到 j 号房间就将数组所对应的位置加一,最后对数组进行降序排序,得到的 第一个位置的count[0]就是重复次数对多的房间,那么我们将其count[0]*10输出就得到移动N张桌子所需要花费的最少时间;

还有个地方要注意:我给的代码,是直接将南北两边的房间合在和一起,因为他们是公用一条走廊的,为了方便程序的编写,就直接将其处理在一起了;

给出代码:




版权声明:本文为博主原创文章,未经博主允许不得转载。

贪心算法-HDU1050-Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

Moving Tables HDU - 1050

Moving Tables HDU - 1050

HDU 1050 Moving Tables 贪心!!

Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

HDU1050_Moving Tables

Moving Tables http://acm.hdu.edu.cn/showproblem.php?pid=1050 Time Limit: 2000/1000 MS (Java/Other...

HDU1050 Moving tables

题目大意:在一个长走廊里面搬桌子,走廊的两侧都是房间,把桌子从一个房间搬到另一个房间,走廊的宽度每次只允许搬一个桌子,每次搬桌子需要10分钟,问最少多长时间办完。 输入:第一个数t代表测试用例,接下里...
  • fyy607
  • fyy607
  • 2015年08月24日 11:37
  • 422

HDU_1050 Moving Tables 【贪心】

题目信息: Moving Tables Problem Description The famous ACM (Advanced Computer Maker) Company has re...

hdu 1050 Moving Tables(贪心算法---区间覆盖,重叠数)

问题描述: The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape...

HDU 1050:Moving Tables【贪心 & 灵活】

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

【贪心专题】HDU 1050 D - Moving Tables (移桌子)

链接:click here~ 题意:在一个长走廊里搬桌子,走廊的两侧都是房间,把桌子从一个房间搬到另外一个房间,走廊的宽度只能允许一个桌子通过,每次搬桌子需要10分钟(每一次允许再不交叉的走廊中同时搬...

hdu1050 Moving Tables

注意,题目的思路是两排房间,,不要最后看成一排了(我一开始就是看成一排滴,所以根本想不出下面这种思想)。 房间是这样的:2,4,6,8,10,……                     ...
  • my1995
  • my1995
  • 2014年07月29日 11:31
  • 168
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU1050 Moving Tables
举报原因:
原因补充:

(最多只允许输入30个字)