Moving Tables

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
    因为有400个房间,1—2共用一段走廊,3—4共用一段走廊,因此我们可以把这整段走廊分成200段,标记为count[1]—count[200],根据输入的房间号,找出要用到哪几段走廊,然后找出count[i]的最大值即可。
参考代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){int T, n, i, cnt[205];scanf("%d",&T);while(T--){scanf("%d",&n);int a, b;memset(cnt, 0, sizeof(cnt));for(i = 0; i < n; i++){scanf("%d%d",&a,&b);a = (a + 1) / 2;b = (b + 1) / 2; //对走廊分段if(a > b)  swap(a, b); //保证a<bfor(int j = a; j <= b; j++)cnt[j]++;}int ans = 0;for(i = 0; i <= 200; i++) //找出最大值ans = max(ans, cnt[i]);printf("%d\n",ans*10);}return 0;
}

hdu 1050 Moving Tables相关推荐

  1. hdu 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 对与每个房间前面过道,操作一次标记一次,标记的最多的次数就是必须用的时间. 1 #include < ...

  2. Moving Tables(贪心)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 原题: Moving Tables Time Limit: 2000/1000 MS (Java/O ...

  3. POJ1083 Moving Tables

    1083:Moving Tables 题目分析:初看似乎像贪心算法中的活动安排问题,不同的是这里的所有活动(相当于搬桌子的距离)都需要安排. 有四种贪心策略:最短优先,最长优先,最早开始时间优先,最早 ...

  4. HDU 1050 NYOJ 220 Moving Tables

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050  http://acm.nyist.net/JudgeOnline/problem.php?pi ...

  5. uva live 2326 - Moving Tables

    把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划, ............ 次数*1 ...

  6. poj 1083 Moving Tables

    题目 两种做法,开始用贪心做的,有种情况没考虑到,结果排序错了. 这个例子,感觉上有三个交点,以为是30,其实是20. 贪心代码: #include <iostream> #include ...

  7. 【POJ1083】 Moving Tables (并行的搬运)

    BUPT2017 wintertraining(15) #6E 题意 房间1和2,3和4,...,399和400共用一节走廊,有q次从房间li到ri的搬运桌子,一次搬运10分钟.两个搬运如果走廊有重叠 ...

  8. POJ-1083 Moving Tables(imos算法)

    这一题有两个陷阱: 给出的起始点可能小于终点 ,所以必须要加个判断,让第二个数大于第一个数 区间算的时候,一定是奇数到偶数,才能做到真正的区间全覆盖.所以如果第二个数是奇数,要加一变为偶数:第一个数为 ...

  9. 你听过算法也是可以贪心的吗?

    点击"阅读原文"直接打开[北京站 | GPU CUDA 进阶课程]报名链接 贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加 ...

最新文章

  1. c++内存中字节对齐问题详解
  2. 使用JavaScript遍历本地文件夹的文件
  3. vtigerCrm 目录结构(整理中)
  4. 【华为云技术分享】Linux内核模块依赖图绘制(2)
  5. python中的OrderedDict
  6. 2d游戏中关于碰撞以及渲染层级关系
  7. 随手记_英语_50大英文经典句/美句
  8. 如何完全卸载MySQL
  9. 汇编语言--DOSBox 0.74的安装与简单使用
  10. 金蝶云星空之表单插件的开发
  11. fpga基础入门知识
  12. 强烈推荐一个有情怀的跨平台Redis可视化客户端工具:RedisViewer
  13. linux搭建tht框架,教程 中标麒麟linux硬盘安装图解
  14. Resend messages one by one
  15. 【应用随机过程】03. 马尔可夫链的状态
  16. 在VMWare虚拟机上安装CentOS 7
  17. e-a乘a的转置的秩_通用矩阵乘(GEMM)优化与卷积计算
  18. 用宝塔面板网站php变成静态,宝塔面板设置伪静态规则
  19. Winform GDI+ 制作连连看,五子棋等(等格子类小游戏 )
  20. matlab音乐合成报告,matlab音乐合成报告

热门文章

  1. A.DongDong破密码
  2. 使用Opencv构建一个简单的图像相似检测器(MSE、SSIM)
  3. 001——数组(一)数组知识及foreach函数应用
  4. Java Web 分页实现
  5. U3D-LookAt插值动画
  6. crontab简单示例
  7. VB100年底测试:McAfee金山遗憾出局 瑞星表现令人意外
  8. 机房日常技术总结——Windows篇
  9. places for finding a consulting job
  10. my current journal index is in q3