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. C# 简单的loading提示控件

    自己画一个转圈圈的控件 using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...

  2. vue-cli新建一个项目

    零.我想把项目安装在C:\www\Arup.DAH.ABCD\SourceCode\FrontEnd这个目录下,所以在我想安装的位置,Shift+右键-->powershell窗口,打开下图位置 ...

  3. Chrome控制台毫无反应,打印不出信息了?

    最近在使用console.log()方法的时候遇到一个奇怪的问题,打开chrome控制台想调试代码,结果控制台半天无反应,让我纳闷了半天.详情如图所示: 然后我又打开了新的标签页,不行!接着干脆关闭浏 ...

  4. <Android 基础(二十一)> Android 屏幕适配

    基本概念 1. 什么是屏幕尺寸.屏幕分辨率.屏幕像素密度? 屏幕尺寸是指屏幕对角线的长度.单位是英寸,1英寸=2.54厘米 屏幕分辨率是指在横纵向上的像素点数,单位是px,1px=1像素点,一般是纵向 ...

  5. 外贸电商的ERP有很多

    经常有人问我:市面上针对外贸电商的ERP有很多,为什么有的卖家用得风生水起,而我却觉得每款都不合适?一般我都是拒绝回答的,一是因为这种情况大多数跟ERP实施有关,很难用短短几千字就说清楚:二是因为我也 ...

  6. linux 命令行模式下,浏览网页方法

    Ubuntu自带最新版的Gnome桌面,拥有大量的服务和桌面应用程序,让您仅通过一张安装光盘就可以体验到无比舒适的操作环境.下文介绍的在ubuntu下使用终端命令行上网的方法. 第一步,需要安装一个名 ...

  7. ActiveMQ queue 代码示例

    生产者: package com.111.activemq; import javax.jms.Connection; import javax.jms.ConnectionFactory; impo ...

  8. JDBC连接数据库反射实现O/R映射

    测试preparedStatement public void testPreparedStatement(){ Connection connection=null; PreparedStateme ...

  9. Python 解决写入csv中间隔一行空行问题

    转载解决写入csv中间隔一行空行问题 写入csv: with open(birth_weight_file,'w') as f: writer=csv.writer(f) writer.writero ...

  10. 网站url常见报错

    报错情况比较复杂,此处列出比较常见的几种报错内容: 报错: 报错是一个大类, 的报错基本上是权限问题,出现 报错时您需要检测权限配置问题. 403.1 错误是由于“执行”访问被禁止而造成的.若试图从目 ...