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 ...
随机推荐
- BZOJ 2006 超级钢琴(划分树+优先队列)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2006 题意: 给出一个数列A,L,R,构造出一个新的集合,集合中的数字为A中任意连续t( ...
- AutoCompleteTextView与TextWatcher的结合
/******************************************************************************************** * au ...
- 如何将开源项目部分代码作为private放在github上?
很多时候,你的一些项目本身都是开源的,但是基于该开源项目,你可能做了部分更有价值的工作,或者由于其他原因,你不希望将这部分代码放到public上,那么有以下简单方法: 1. 创建一个private b ...
- 软件设计之UML—UML的构成[上]
UML是一种通用的建模语言,其表达能力相当的强,不仅可以用于软件系统的建模,而且可用于业务建模以及其它非软件系统建模.UML综合了各种面向对象方法与表示法的优点,至提出之日起就受到了广泛的重视并得到了 ...
- Web程序员最常用的11款PHP框架
PHP框架是Web程序员和开发人员最为有用的工具. PHP框架可以帮助用户更快地开发项目. 今天我将为开发人员带来几款最好的PHP框架,希望能对你有用. 1.Agavi Agavi是一款强大的,可扩展 ...
- ucosII移植
移植ucos II 到一个芯片上,只需要修改下面三个文件:OS_CPU.H,OS_CPU_C.C,OS_CPU_A.ASM. 具体来说,移植主要包括以下几项内容 (1).OS_CPU.H :用#def ...
- mysql mac启动
设置别名 alias mysql=/usr/local/mysql/bin/mysql alias mysqladmin=/usr/local/mysql/bin/mysqladmin 修改密码 su ...
- swun 1766 我的悲剧不可能那么好数
解题思路: 一向提交特别慎重的我,这题竟然PE了5发左右,放了几天,再回来写,直接1A, 相当的自豪,而且是最优解题者.这题千万要注意,化繁为简,文章只包括大小 写字母和数字,还有空行. #inc ...
- 今天开始自学Andrew Ng的机器学习,希望可以坚持下来
今天开始正式接触机器学习,20集的课程争取在开学前看完.每看完一集会在博客记录笔记,加油! 版权声明:本文为博主原创文章,未经博主允许不得转载.
- 给产品经理讲技术,不得不懂的TCP和UDP
TCP/IP协议,你一定经常听说吧,其中TCP(Transmission Control Protocol)称为传输控制协议,IP(Internet Protocol)称为因特网互联协议,好吧,这都是 ...