Moving Tables

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f struct node
{
int a,b,flag;
} p[10000]; bool cmp(node a,node b)
{
return a.a<b.a;
} int main()
{
int m,t,n;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
memset(p,0,sizeof p);
for(int i=0; i<n; i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
if(p[i].a>p[i].b)
swap(p[i].a,p[i].b);
if(p[i].a%2==0)
p[i].a--;
if(p[i].b%2)
p[i].b++;
}
sort(p,p+n,cmp);
int cnt=0;
int ans=0; for(int i=0; i<n; i++)
{
if(p[i].flag==0)
{
ans++;
p[i].flag=1;
int cur=i;
int k=i;
while(k<n)
{
if(p[k].a>p[cur].b&&p[k].flag==0)
{
cur=k;
p[cur].flag=1;
}
k++;
}
}
}
printf("%d\n",ans*10);
}
}
return 0;
}

Hdu1050 Moving Tables 2016-05-19 16:08 87人阅读 评论(0) 收藏的更多相关文章

  1. SQL 存储过程 通过多个ID更新数据 分类: SQL Server 2014-12-08 16:08 299人阅读 评论(0) 收藏

    下面举个例子说明: 我想让一部分品牌的名称(即Brand_Name)后面加上1,Brand_ID是主键,sql语句很容易实现,但是存储过程如何写呢? 错误写法如下: //*************** ...

  2. 【solr专题之四】在Tomcat 中部署Solr4.x 分类: H_HISTORY 2014-07-17 16:08 1286人阅读 评论(0) 收藏

    1.安装Tomcat (1)下载并解压至/opt/tomcat中 # cd /opt/jediael # tar -zxvf apache-tomcat-7.0.54.tar.gz # mv apac ...

  3. Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏

    Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...

  4. OC基础:block.字面量 分类: ios学习 OC 2015-06-22 19:08 155人阅读 评论(0) 收藏

    block 块语法,可以用block去保存一段代码,或者封装一段代码. block 实际是由c语言实现的,执行效率很高. block 实际借鉴了函数指针的语法. block,在多线程.异步任务,集合遍 ...

  5. 烂漫爱心表白动画 分类: C# 2014-10-07 19:08 28人阅读 评论(0) 收藏

    曾经我说过我会用程序来表达我对你的爱. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  6. 网上关于sort结构体排序都不完整,我来写一个完整版的 2014-08-09 16:50 60人阅读 评论(0) 收藏

    主要参考sort函数_百度文库, 但是那篇有错误 2.结构体排序,a升,b降,c降 平板视图 打印? 01 #include <iostream> 02 #include <algo ...

  7. C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏

    //欲练此功必先自宫!!!     //第一天:C语言的基础     //进制     //2进制, 10进制, 8进制, 16进制     //注:8进制数前加0, 16进制数前加0x        ...

  8. NavBarControl控件 2015-07-23 16:56 2人阅读 评论(0) 收藏

    NavBarControl控件 1.      新建一个windows窗体应用程序项目 2.      在工具箱中的Navigation& Layout选项卡下找到NavBarControl, ...

  9. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

随机推荐

  1. mysql in 过滤 解决转义问题

    IF(headUser!='',instr(concat(',',headUser,','),concat(',',cr.headUser,',')),TRUE);

  2. MySql PartionBy

    SELECT tableOld.*, if(@channelName = tableOld.channelName, @rank := @rank + 1, @rank := 1) AS rank, ...

  3. JSP通过表格显示数据库的信息

    [step one] 1-1 建立数据库 在jsp中,我们使用的是mysql数据库,对于此数据的优缺点本篇不予以讲述,首先建立news数据库,其数据库中表的信息为: eg:< id :1 ; n ...

  4. Mybatis中传入时间值

    <if test="search_content2 != null and search_content2 != ''"> AND add_time <![CDA ...

  5. poj1182(带权并查集)

    题目链接:http://poj.org/problem?id=1182 题意:题目告诉有  3  种动物,互相吃与被吃,现在告诉你  m  句话,其中有真有假,叫你判断假的个数  (  如果前面没有与 ...

  6. ArrayList LinkList比较

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.      2.对于随机访问get和set,ArrayList优于LinkedList,因为ArrayLi ...

  7. SQL时间格式化 转载备用~

    Sel1 取值后格式化{0:d}小型:如2005-5-6{0:D}大型:如2005年5月6日{0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...

  8. iOS 多页面跳转同一页面时数据处理

    如果 同一个界面, 会有10个数据源传进来, 此时 创建 一个总模型fullmodel 存储 10个model 数据, 创建 10个一样的cell, 在 不同数据, 用不同cell处理最好, 千万别于 ...

  9. 设置 svn 与 web线上同步

    默认你已经配置好了svn服务 1.假设我们的线上网站目录为:/data/www/xxx 2.假设svn的仓库目录为:/data/svn/repo 一.checkout一份svn到线上网站目录 svn ...

  10. 获取验证码效果和后台代码(js+html+cs)

    客户端js+html代码 <script type="text/javascript"> var tcode = 0;//定时器返回代码 //获得验证码 functio ...