Hdoj 1050.Moving Tables 题解
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
Asia 2001, Taejon (South Korea)
思路
两个思路:
- 把移动的房间号\(l,r\)看成平面上的一条线段,要找的就是最大重叠次数,此处刚好范围也比较小,所以可以用这个方法
- 用贪心的思想,有点像Hdoj 2037.今年暑假不AC(https://www.cnblogs.com/MartinLwx/p/9727939.html)这道题目,具体思路可以看这个
代码(思路一)
#include<bits/stdc++.h>
using namespace std;
int a[210];
int cor(int x)
{
return x%2==0 ? x/2 : (x+1)/2;
}//返回走廊位置
int main()
{
int t;
while(cin>>t)
{
for(int i=1;i<=t;i++)
{
int n;
cin >> n;
int l,r;
memset(a,0,sizeof(a));
for(int j=1;j<=n;j++)
{
scanf("%d%d",&l,&r);
if(l>r)
{
int t;
t = l; l = r; r = t;
}
int corl = cor(l);
int corr = cor(r);
for(int k=corl;k<=corr;k++)
a[k]++;
}
//for(int j=1;j<=30;j++) cout<<a[j]<<" ";
int max_value = -1;
for(int j=1;j<=201;j++)
if(a[j]>max_value)
max_value = a[j];
if(max_value==0)
cout << 10 << endl;
else
cout << max_value*10 << endl;
}
}
return 0;
}
Hdoj 1050.Moving Tables 题解的更多相关文章
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1083 && HDU 1050 Moving Tables (贪心)
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 【HDOJ】1050 Moving Tables
贪心问题,其实我觉得贪心就是合理的考虑最优情况,证明贪心可行即可.这题目没话多久一次ac.这道题需要注意房间号的奇偶性.1 3.2 4的测试数据.答案应该为20. #include <stdio ...
- HDU ACM 1050 Moving Tables
Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...
- hdu 1050 Moving Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- --hdu 1050 Moving Tables(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...
随机推荐
- python 实现快速排序
一.快排思想 快速排序可以理解为是对冒泡排序的一种改进,把一组数,按照初始选定的标杆(参照数), 分别从两端开始排序,左端'i'只要小于标杆(参照数)的数,右端'j'只要大于标杆(参照数)的数, i- ...
- vue-cli脚手架安装和webpack-simple模板项目生成
vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...
- Linux中profile
http://www.cnblogs.com/mmfzmd517528/archive/2012/07/05/2577988.html
- VS2008引入头文件包含目录和lib库目录
全局级别的引入 为VS所有项目设置包含目录和库目录,对所有项目都有效 如下图所示:工具-选项-项目和解决方案-VC++目录-包含文件:在此添加头文件目录即可 工具-选项-项目和解决方案-VC++目录- ...
- 简要了解 MySql 5.5/5.6/5.7/8 出现的新特性
MySQL的开发周期 在比较之前,首先提一下MySQL的开发周期. MySQL一个大版本的开发,大致经历如下几个阶段: Feature Development Feature Testing Perf ...
- MySQL数据类型优化—整数类型优化选择
原文:http://bbs.landingbj.com/t-0-240002-1.html 在设计数据库的时候,整数类型的使用时不可避免的如ID,类型等. 在选择整数的同时主要是考虑是数据范围,如是否 ...
- java 获取下一个字母(传大写返回大写,传小写返回小写)
public static String getNextUpEn(String en){ char lastE = 'a'; char st = en.toCharArray()[0]; if(Cha ...
- js判断是否是微信浏览器以及重定向
async created () {//这个是判断是否是微信浏览器, let ua = navigator.userAgent.toLowerCase() if (ua.match(/MicroMes ...
- Android——MaterialDesign之三NavigationView
NavigationView的使用 这里我们来讲讲在Android5.0之后推出的NavigationView的具体使用方式.和普通的侧拉菜单制作方式一样,首先所有的东西还是都放在一个DrawerLa ...
- python爬虫之Gerapy安装部署
原创北航大才:https://cuiqingcai.com/5006.html NULL:http://www.infosec-wiki.com/?p=432737