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

Source

Asia 2001, Taejon (South Korea)


思路

两个思路:

代码(思路一)

#include<bits/stdc++.h>
using namespace std;
int a[210];
int cor(int x)
{
return x%2==0 ? x/2 : (x+1)/2;
}//返回走廊位置
int main()
{
int t;
while(cin>>t)
{
for(int i=1;i<=t;i++)
{
int n;
cin >> n;
int l,r;
memset(a,0,sizeof(a));
for(int j=1;j<=n;j++)
{
scanf("%d%d",&l,&r);
if(l>r)
{
int t;
t = l; l = r; r = t;
}
int corl = cor(l);
int corr = cor(r);
for(int k=corl;k<=corr;k++)
a[k]++;
}
//for(int j=1;j<=30;j++) cout<<a[j]<<" ";
int max_value = -1;
for(int j=1;j<=201;j++)
if(a[j]>max_value)
max_value = a[j]; if(max_value==0)
cout << 10 << endl;
else
cout << max_value*10 << endl;
}
}
return 0;
}

Hdoj 1050.Moving Tables 题解的更多相关文章

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

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

  2. HDOJ 1050 Moving Tables

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

  3. 1050 Moving Tables

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

  4. 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 ...

  5. 【HDOJ】1050 Moving Tables

    贪心问题,其实我觉得贪心就是合理的考虑最优情况,证明贪心可行即可.这题目没话多久一次ac.这道题需要注意房间号的奇偶性.1 3.2 4的测试数据.答案应该为20. #include <stdio ...

  6. HDU ACM 1050 Moving Tables

    Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...

  7. hdu 1050 Moving Tables 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...

  8. HDU – 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...

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

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

随机推荐

  1. HDU 2006 求奇数的乘积

    http://acm.hdu.edu.cn/showproblem.php?pid=2006 Problem Description 给你n个整数,求他们中所有奇数的乘积.   Input 输入数据包 ...

  2. day 7-20 视图,触发器,事务

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  3. (二)类数组对象HTMLCollection

    HTMLCollection 表示 HTML 元素的集合. 下面的几种方式将返回 HTMLCollection对象: html: <body> <ul id="box&qu ...

  4. C# Note18: 使用wpf制作about dialog(关于对话框)

    前言 基本上任何software或application都会在help菜单中,有着一个关于对话框,介绍产品的版权.版本等信息,还有就是对第三方的引用(add author credits). 首先,看 ...

  5. Laravel 出现 No application encryption key has been specified.

    若文件根目录下没有 .env 1..env.example 改名使用命令 copy 修改为 .env 2.使用命令 php artisan key:generate  获取密码,自动保存到 .env3 ...

  6. Java多线程之线程状态转换图

    说明:线程共包括以下5种状态.1. 新建状态(New)         : 线程对象被创建后,就进入了新建状态.例如,Thread thread = new Thread().2. 就绪状态(Runn ...

  7. cuda编程视频资料

    胡文美教授 http://www.gpuworld.cn/article/show/463.html

  8. Nginx http反向代理流程Proxy_pass模块

    L:88 反向代理代码示列 server { listen ; server_name shop**.com.cn; location /{ proxy_pass http://test/www; p ...

  9. 3、springframe常用注解

    1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  10. BZOJ2658 ZJOI2012 小蓝的好友(treap)

    显然转化为求不包含关键点的矩形个数.考虑暴力,枚举矩形下边界,求出该行每个位置对应的最低障碍点高度,对其建笛卡尔树,答案即为Σhi*(slson+1)*(srson+1),即考虑跨过该位置的矩形个数. ...