Moving Tables

Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563

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
一开始一直以为要把那么多椅子搬完,应该按照谁结束时间最早来排序,结果wa到死。
后来终于醒悟过来orz,要把所有椅子尽可能搬完,应该尽可能利用他给这段区间。(就是说令每一次10分钟的搬运,所使用的区间尽可能去占满整段区间)
所以按照开始的位置进行排布即可。

zstu.2512. Moving Tables(贪心)的更多相关文章

  1. Moving Tables(贪心或Dp POJ1083)

    Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28304   Accepted: 9446 De ...

  2. HDU1050(Moving Tables:贪心算法)

    解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...

  3. hdu_1050 Moving Tables 贪心

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

  4. UVAlive 2326 Moving Tables(贪心 + 区间问题)

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

  5. --hdu 1050 Moving Tables(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...

  6. POJ 1083 &amp;&amp; HDU 1050 Moving Tables (贪心)

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

  7. hdoj 1050 Moving Tables【贪心区间覆盖】

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

  8. HDOJ 1050 Moving Tables

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

  9. Moving Tables

    Moving Tables Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. 使用uWSGI部署django项目

    先说说什么是uWSGI吧,他是实现了WSGI协议.uwsgi.http等协议的一个web服务器,那什么是WSGI呢? WSGI是一种Web服务器网关接口.它是一个Web服务器(如nginx)与应用服务 ...

  2. ubuntu下的ssh

    ubuntu默认是没有安装openssh-server的,今天简单的写一下ubuntu上ssh的安装与使用. 一.服务器端 安装 apt-get install openssh-server #安装 ...

  3. 高可用与负载均衡(6)之聊聊LVS的三种模式

    LVS的赘述 IPVS,ipvs ,ip_vs是负载均衡器中的内核代码 LVS是完整的负载均衡器+后端服务器.这些组件组成了虚拟服务器. LVS是一个4层负载均衡方案,标准的客户端-服务器网络语义也被 ...

  4. log4net详解(转载)

    1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...

  5. C#------各种常见错误解决方法

    1.错误:模型生成过程中检测到一个或多个验证错误 表示实体中的数据列没有和SQLServer数据库里面的表中的数据列完全相同,比如SQLServer中有ID,Name,Post,那么实体中也应该有ID ...

  6. ORACLE ORA-01157: 无法标识/锁定数据文件

    create undo tablespace MOZI datafile 'E:\oracle\product\10.2.0\oradata\orcl\MOZI.DBF' size 2048M ext ...

  7. dos命令复制当天生成的以日期为文件名的文件

    1.利用SqlServer的自动备份功能,将数据自动备份,备份出的文件格式如下:             db_backup_201001270930.bak 2.编辑bat脚本            ...

  8. delphi SQL操作

    create表 时不可以有类似Name之类的字段创建,否则报错,即使access数据库中执行正常   insert的字符型字段中不可以有英文单引号 ' 之类的存在,否则报错,可以用#39 代替,减少英 ...

  9. centos6.5yum方式升级内核

    升级内核需要使用elrepo的yum源,在安装yum源之前还需要我们导入elrepo的key,如下:rpm -import https://www.elrepo.org/RPM-GPG-KEY-elr ...

  10. 计算div里面li个数

    方式一:js var content=document.getElementById("content"); alert(document.getElementsByTagName ...