Moving Tables

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

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

这道题目很有意思!所以拿上来了!

贴代码说明自己太懒了!

别人的思路!

其实重合线段最多的一部分就是答案!这个仔细想想!

因为重合多的地方一定要分开弄!

注意:房间一侧都是隔着1个数!

所以还要预处理下!

主要代码:  

   if (x>y) swap(x,y);
        int xx,yy;
        if (x%2==1) xx=(x-1)/2+1;
        else xx=x/2;
        if (y%2==1) yy=(y-1)/2+1;
        else yy=y/2;
        for (int j=xx;j<=yy;j++)
        f[j]++;
       }

HDOJ1050的更多相关文章

  1. hdoj1050 Moving Tables(贪心)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1050 题意 有一条走廊,走廊两边各有200个房间,一边的房间编号是奇数,另一边是偶数.现在有n个箱子需 ...

随机推荐

  1. 为你的Windows7设置动态壁纸

    From:http://www.cnblogs.com/killerlegend/p/3644014.html By KillerLegend DreamScene是Vista上的一个功能,可以让你设 ...

  2. jquery.unobtrusive-ajax.js源码阅读

    /*! ** Unobtrusive Ajax support library for jQuery ** Copyright (C) Microsoft Corporation. All right ...

  3. laravel 笔记

    1.excel composer require maatwebsite/excel ~2.0.0 Maatwebsite\Excel\ExcelServiceProvider::class, 'Ex ...

  4. node.js web开发:EXPRESS 4.x 以上使用session和cookie 的记录

    关于session 和cookie 我搞了2-3天, 发现这个玩意也挺麻烦的. 很多教程都是把这种会话保存在nosql里面,比如mongo,或者redis等等.但是我还是想直接保存在计算机的内存中,比 ...

  5. 菜鸟学习Hibernate——配置Hibernate环境

    一.概念. Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库.既然学习Hibernate那么第 ...

  6. BASE64与单向加密算法MD5&SHA&MAC

    言归正传,这里我们主要描述Java已经实现的一些加密解密算法,最后介绍数字证书.     如基本的单向加密算法: BASE64 严格地说,属于编码格式,而非加密算法 MD5(Message Diges ...

  7. Android中如何获取应用版本号

  8. ssh公钥免密码登录

    1,生成公钥 ssh-keygen -t rsa 2,上传至服务器 将个人电脑的公钥添加到服务器 cat id_rsa.pub >> ~/.ssh/authorized_keys 3,本地 ...

  9. 使用spring dynamic modules的理由

    spring的主要功能 spring框架提供了轻量级的容器和非侵入式的编程模型,这来自于其依赖注入.AOP和便携服务概念. osgi的主要功能 osgi服务平台提供了动态的应用程序执行环境,支持模块( ...

  10. 如何查看hadoop与hbase的版本匹配关系

    官网:http://hbase.apache.org/book.html 搜索:Hadoop version support matrix 下面有一个二维的支持关系表.