Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 20302    Accepted Submission(s): 6889

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
  1. 3
  2. 4
  3. 10 20
  4. 30 40
  5. 50 60
  6. 70 80
  7. 2
  8. 1 3
  9. 2 200
  10. 3
  11. 10 100
  12. 20 80
  13. 30 50
 
Sample Output
  1. 10
  2. 20
  3. 30
 
Source

解题思路:贪心。考虑每次的最优解,则对面的两房间共有它们所相应的区域,每次交错,都会产生一次冲突,就代表他们不能在同一次搬运,考虑到多次转移的交错的区域,最大交错的次数就代表了最小的搬运次数。

AC代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. int room[205];
  9.  
  10. int main(){
  11. // freopen("in.txt", "r", stdin);
  12. int t, n, x, y;
  13. scanf("%d", &t);
  14. while(t--){
  15. memset(room, 0, sizeof(room));
  16. scanf("%d", &n);
  17. for(int i=0; i<n; i++){
  18. scanf("%d%d", &x, &y);
  19. if(x > y) swap(x, y); //防止起始房间大于终止房间
  20. for(int i=(x+1)/2; i<=(y+1)/2; i++){
  21. room[i] ++; //相应区域的交错次数添加
  22. }
  23. }
  24. int ans = 0;
  25. for(int i=1; i<=201; i++){
  26. if(ans < room[i]) ans = room[i];
  27. }
  28. printf("%d\n", ans*10);
  29. }
  30. return 0;
  31. }

POJ 1083 &amp;&amp; HDU 1050 Moving Tables (贪心)的更多相关文章

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

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

  2. hdu 1050 Moving Tables 解题报告

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

  3. hdu 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 这个题我首先直接用的常规贪心,用的和那个尽可能看更多完整节目那种思路.但是.......一直WA....T ...

  4. HDU – 1050 Moving Tables

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

  5. hdu 1050 Moving Tables (Greedy)

    Problem - 1050 过两天要给12的讲贪心,于是就做一下水贪心练习练习. 代码如下: #include <cstdio> #include <iostream> #i ...

  6. HDU 1050 Moving Tables (贪心)

    题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...

  7. hdu 1050 Moving Tables(迷之贪心...)

    题意:有400间房间按题目中图片所给的方式排列,然后给出要移动的n张桌子所要移动的范围,每张桌子要移动的范围不能出现重叠的区域:问最少要多少次才能移动完所有的桌子. 题解思路:把题目转换下,就是有n个 ...

  8. hdu 1050 Moving Tables_贪心

    题意:你搬n个桌子,桌子从一个地方搬到另一个地方,走廊只允许同时一个桌子通过,教室分布在两边,奇数在一边,偶数在一边,当桌子不冲突时可以同时搬运,冲突时要等别的那个桌子搬完再搬. 思路:因为奇数桌子在 ...

  9. HDOJ 1050 Moving Tables

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

随机推荐

  1. 时间格式的处理和数据填充和分页---laravel

    时间格式文档地址:http://carbon.nesbot.com/docs/ 这是些时间格式,只需要我们这么做就可以 我们在模板层,找到对应的模型对象那里进行处理就可以啦 2018-11-08 16 ...

  2. Python中如何将数据存储为json格式的文件(续)

    将上一篇中的例子,修改一下,将两个程序合二为一,如果存储了用户喜欢的水果就显示它,否则提示用户输入他喜欢的水果并将其存储到文件中. favorite.py import json filename = ...

  3. LeetCode(137) Single Number II

    题目 Given an array of integers, every element appears three times except for one. Find that single on ...

  4. CentOS安装mysql5.6

    1. 去官网https://dev.mysql.com/downloads/mysql/5.6.html下载mysql压缩包,选第一个,最大最全的 2. 通过FTP工具比如FileZila存放到目标地 ...

  5. python基础学习笔记——闭包

    闭包这个概念好难理解,身边朋友们好多都稀里糊涂的,稀里糊涂的林老冷希望写下这篇文章能够对稀里糊涂的伙伴们有一些帮助~ 请大家跟我理解一下,如果在一个函数的内部定义了另一个函数,外部的我们叫他外函数,内 ...

  6. python3--__radd__处理右侧加法

    __radd__处理右侧加法 从严格意义上来讲,前边例子中出现的__add__方法并不支持+运算符右侧使用实例对象.要实现这类表达式,而支持可互换的运算符,可以一并编写__radd__方法.+右侧的对 ...

  7. 九度oj 题目1048:判断三角形类型

    题目描述: 给定三角形的三条边,a,b,c.判断该三角形类型. 输入: 测试数据有多组,每组输入三角形的三条边. 输出: 对于每组输入,输出直角三角形.锐角三角形.或是钝角三角形. 样例输入: 3 4 ...

  8. JS 调用存储过程传递参数

    引用 #region 程序集 Newtonsoft.Json.dll, v4.5.0.0 // E:\Newtonsoft.Json.dll #endregion public DataTable R ...

  9. rabbitmq php 学习

    参考文档:http://www.cnblogs.com/phpinfo/p/4104551...http://blog.csdn.net/historyasamirror/ar... 依赖包安装 yu ...

  10. py 爬取页面http://m.sohu.com 并存储

             usage()               opts,args = getopt.getopt(sys.argv[1:],                        usage( ...