HDU ACM 1050 Moving Tables
Problem Description
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.
125 158
176 48
196 65
21 171
15 170
17 100
61 116
3 189
98 104
112 19
163 66
42 14
81 168
53 165
36 143
84 140
105 199
195 151
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SIZE 404 using namespace std; typedef struct item{
int begin, end;
}item;
item room[SIZE];
bool visit[SIZE];
int n; bool cmp(const item& a, const item& b)
{
return a.begin < b.begin;
} void Traverse(int cnt, int sum)
{
if(sum == n)
{
printf("%d\n", cnt*);
return;
}
int temp = , count = ;
for(int i=; i<n; ++i)
{
if(!visit[i] && temp < room[i].begin)
{
count++;
temp = room[i].end;
visit[i] = true;
}
}
Traverse(cnt+, sum+count);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int T, left, right;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<n; ++i)
{
scanf("%d", &left);
room[i].begin = left = left + (left % );
scanf("%d", &right);
room[i].end = right = right + (right % );
if(left > right)
{
room[i].begin = right;
room[i].end = left;
}
}
memset(visit, false, sizeof(visit));
sort(room, room+n, cmp);
Traverse(, );
}
}
HDU ACM 1050 Moving Tables的更多相关文章
- 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
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 ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 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 code: #include<stdio.h> #include<str ...
- hdu 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 这个题我首先直接用的常规贪心,用的和那个尽可能看更多完整节目那种思路.但是.......一直WA....T ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- hdu 1050 Moving Tables (Greedy)
Problem - 1050 过两天要给12的讲贪心,于是就做一下水贪心练习练习. 代码如下: #include <cstdio> #include <iostream> #i ...
随机推荐
- 《OD学hive》第六周20160731
一.hive的压缩 1. hadoop的压缩 1)为什么需要压缩 MapReduce的性能瓶颈:网络IO.磁盘IO 数据量:对于MapReduce的优化,最主要.根本就是要能够减少数据量 Combin ...
- How to install Node.js on Linux
How to install Node.js on Linux Posted on November 13, 2015 by Dan Nanni Leave a comment Question: H ...
- UVa 839 (递归方式读取二叉树) Not so Mobile
题意: 递归的方式输入一个树状天平(一个天平下面挂的不一定是砝码还可能是一个子天平),判断这个天平是否能满足平衡条件,即W1 * D1 == W2 * D2. 递归的方式处理输入数据感觉很巧妙,我虽然 ...
- HDFS常用命令
HDFS 常用的文件操作命令 hdfs dfs -text /pub/20151019/1/4/gwmvod/mediags.moretv.com.cn/*.bz2 | wc -l hdfs dfs ...
- BZOJ 1176 MOKIA
cdq分治. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...
- MySQL表类型
学习Mysql数据库,Mysql表类型都有哪些是一定需要知道的,下面就为您介绍七种Mysql表类型,希望能对您学习Mysql表类型有所帮助. MySQL作为当前最为流行的免费数据库服务引擎,已经风靡了 ...
- linux下安装虚拟机qemu kqemu
一,为什么要装虚拟机,为什么选择qemu 我的系统里面有3个linux系统,这些系统都是独立的,有的时候,我想一台电脑,能更真实的模拟二台,这个时候我们就可以装个虚拟机.其实如果真的很有钱的话,可能考 ...
- exp/imp使用
[sql]view plaincopy 1.EXP: 1.完全: EXP SYSTEM/MANAGER BUFFER=64000 FILE=C:\FULL.DMP FULL=Y 如果要执行完 ...
- Axis,axis2,Xfire以及cxf对比
http://ws.apache.org/axis/ http://axis.apache.org/axis2/java/core/ http://xfire.codehaus.org/ http:/ ...
- Effective java笔记4--方法
一.检查参数的有效性 极大多数方法和构造函数都会对于传递给它们的参数值有某些限制. 对于公有的方法,使用Javadoc @throws标签(tag)可以使文档中记录下“一旦针对参数值的限制被违反之后将 ...