Moving Tables

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

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
 
题目意思:
一层楼 400个房间,编号从1到400,分成两行,奇数一行,偶数一行,一条走廊在两排房间的中间,现在要从一共房间往另外一共房间搬桌子,由于走廊太窄,一次只能通过一张桌子,所以有重叠走廊段的桌子不能在同一个回合搬,问你搬完全部桌子,需要多少分钟?每个回合10分钟
 
解法:
搬桌子经过的走廊段不就是要经过这些走廊段中房间的门口吗?
400个房间,400个门口,两两个是相对的,所以看成200个门口
搬桌子经过该段就是经过该段的所有门口,经过的门口中经过次数最多门口的经过次数不就是我们需要的回合数吗?
注意:
 门口数组初始化全0,经过一次就++
找到门口中经过门口次数最大的门口中的经过次数就是我们需要的回合数
3,4是对门,看成同一个门口,这就是为什么
 a=(a+1)/2;
 b=(b+1)/2;
的原因
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define max_v 205
int f[max_v];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
memset(f,,sizeof(f));
for(int i=; i<n; i++)
{
int a,b;
scanf("%d %d",&a,&b);
if(a>b)
{
int t=a;
a=b;
b=t;
}
a=(a+)/;
b=(b+)/;
for(int i=a;i<=b;i++)
{
f[i]++;
}
}
int t=;
for(int i=;i<max_v;i++)
{
if(t<f[i])
{
t=f[i];
}
}
printf("%d\n",t*);
}
return ;
}
 

HDU 1050(楼道搬桌子问题)(不是贪心解法,思路很新颖)的更多相关文章

  1. HDU 1050(搬椅子 数学)

    题意是在一个有 400 个房间的走廊中搬动房间里的椅子,如果两次的路线重叠,就要分两次搬动,如果不重叠,就可以一次搬动. 开始的时候直接当成求线段重叠条数的题,发现这种思路完全是错的,比如 1 - 3 ...

  2. HDU – 1050 Moving Tables

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

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

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

  4. hdu 1050 Moving Tables 解题报告

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

  5. hdu 1050 Moving Tables

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

  6. hdu 1050 Moving Tables_贪心

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

  7. HDU 1050 Moving Tables (贪心)

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

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

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

  9. hdu 1050 Moving Tables (Greedy)

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

随机推荐

  1. JDBC入门(5)--- 时间类型、大数据

    一.时间类型 数据库类型与Java中类型的对应关系: DATE->java.sql.Date:表示日期,只有年月日,没有时分秒,会丢失时间. TIME->java.sql.Time:表示时 ...

  2. CentOS6下docker的安装和使用

    CentOS6下docker的安装和使用 Docker是一个开源的应用容器引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.利用Linux的LXC.AUFS.Go语言.cgroup ...

  3. 13 Reasons Why You Should Pay Attention to Mobile Web Performance

    Mobile is no longer on the sidelines. If you’re not already thinking mobile first, you should at lea ...

  4. MySQL数据库(9)----使用连接实现多表检索

    有许多演示如何使用MySQL所支持的连接操作的示例,都用到了下列两个表 t1 和 t2: mysql> SELECT * FROM t1; +----+------+ | i1 | c1 | + ...

  5. mysql性能问题小解 Converting HEAP to MyIsam create_myisa

    安定北京被性能测试困扰了N天,实在没想法去解决了,今天又收到上级的命令说安定北京要解决,无奈!把项目组唯一的DBA辞掉了,现在所以数据库的问题都得自己来处理:( 不知道上边人怎么想的.而且更不知道怎安 ...

  6. [转]开源日志库<log4cplus+VS2008使用>整理

    转 开源日志库<log4cplus+VS2008使用>整理 转http://pyhcx.blog.51cto.com/713166/143549 一.简介     log4cplus是C+ ...

  7. _tcsrchr

    原文:http://www.cnblogs.com/diyunpeng/archive/2012/01/18/2325289.html _tcsrchr #include <afx.h> ...

  8. Evernote Markdown Sublime实现

    版权声明: 欢迎转载,但请保留文章原始出处 作者:GavinCT 出处:http://www.cnblogs.com/ct2011/p/3996164.html Evernote无法实现markdow ...

  9. 【PHP系列】PHP 7.0新增特性详解

    开始介绍PHP7.0新特性,具体的可以参照官网的介绍,我来挑一些给大家详细讲解下 http://php.net/manual/en/migration70.new-features.php 1. ?? ...

  10. byr面经两则

    人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经 首先感谢师兄在两年前发的贴([天道酬勤] 腾讯.百度.网易游戏.华为Offer及笔经面经 ),这篇文章对我帮助很大. 我写这篇文章一是为了感 ...