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. 《JavaWeb从入门到改行》注册时向指定邮箱发送邮件激活

    javaMail API javaMail是SUN公司提供的针对邮件的API . 两个jar包  mail.jar 和 activation.jar java mail中主要类:javax.mail. ...

  2. Bash:获取当前脚本路径

    可以使用readlink命令必须加上-f参数,readlink用于读取链接文件所指向的文件,这样对于一些建立了软连接的脚本文件的话非常适用,而对于一般的脚本文件需要加上-f参数否则readlink文件 ...

  3. 洛谷 P2469 [SDOI2010]星际竞速 解题报告

    题目描述 10年一度的银河系赛车大赛又要开始了.作为全银河最盛大的活动之一,夺得这个项目的冠军无疑是很多人的梦想,来自杰森座α星的悠悠也是其中之一. 赛车大赛的赛场由N颗行星和M条双向星际航路构成,其 ...

  4. 微信小程序开发7-JavaScript脚本

    1.小程序的主要开发语言是 JavaScript ,开发者使用 JavaScript 来开发业务逻辑以及调用小程序的 API 来完成业务需求. 2.ECMAScript 在大部分开发者看来,ECMAS ...

  5. Jarvis OJ-Reverse题目Writeup

    做一道更一道吧233333 DD-Android Easy 下载apk,先安装一下试试吧…… 猜测是输入正确的内容后给flag吧 将后缀改成zip,解压,用dex2jar处理classes.dex,然 ...

  6. spring mvc拦截器HandlerInterceptor

    本文主要介绍springmvc中的拦截器,包括拦截器定义和的配置,然后演示了一个链式拦截的测试示例,最后通过一个登录认证的例子展示了拦截器的应用 拦截定义 定义拦截器,实现HandlerInterce ...

  7. Anaconda管理多版本的python环境

    通过Conda的环境管理功能,我们能同时安装多个不同版本的Python,并能根据需要自由切换.下面我将给大家分享一下,新增Python版本,切换,再切回主版本的详细过程. 方法/步骤   1 首先确保 ...

  8. yum 安装LAMP

    一.安装 MySQL 首先来进行 MySQL 的安装.打开超级终端,输入: [root@localhost ~]# yum install mysql mysql-server 安装完毕,让 MySQ ...

  9. 基于双下划线的跨表查询 (join查询)

    因为你的数据库中的查询就是重点  那么你的django提供的orm也是查询语句最重点 ,也提供的查询方法比较的多,下面我们学习下类似于MYSQL的连表(join)查询 Django 还提供了一种直观而 ...

  10. 最优化 KKT条件

    对于约束优化问题: 拉格朗日公式: 其KKT条件为: 求解 x.α.β 其中β*g(x)为互补松弛条件 KKT条件是使一组解成为最优解的必要条件,当原问题是凸问题的时候,KKT条件也是充分条件.