hdu 1050 Moving Tables
Moving Tables
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
Input
Output
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
因为有400个房间,1—2共用一段走廊,3—4共用一段走廊,因此我们可以把这整段走廊分成200段,标记为count[1]—count[200],根据输入的房间号,找出要用到哪几段走廊,然后找出count[i]的最大值即可。
参考代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){int T, n, i, cnt[205];scanf("%d",&T);while(T--){scanf("%d",&n);int a, b;memset(cnt, 0, sizeof(cnt));for(i = 0; i < n; i++){scanf("%d%d",&a,&b);a = (a + 1) / 2;b = (b + 1) / 2; //对走廊分段if(a > b) swap(a, b); //保证a<bfor(int j = a; j <= b; j++)cnt[j]++;}int ans = 0;for(i = 0; i <= 200; i++) //找出最大值ans = max(ans, cnt[i]);printf("%d\n",ans*10);}return 0;
}
hdu 1050 Moving Tables相关推荐
- hdu 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 对与每个房间前面过道,操作一次标记一次,标记的最多的次数就是必须用的时间. 1 #include < ...
- Moving Tables(贪心)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 原题: Moving Tables Time Limit: 2000/1000 MS (Java/O ...
- POJ1083 Moving Tables
1083:Moving Tables 题目分析:初看似乎像贪心算法中的活动安排问题,不同的是这里的所有活动(相当于搬桌子的距离)都需要安排. 有四种贪心策略:最短优先,最长优先,最早开始时间优先,最早 ...
- HDU 1050 NYOJ 220 Moving Tables
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 http://acm.nyist.net/JudgeOnline/problem.php?pi ...
- uva live 2326 - Moving Tables
把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划, ............ 次数*1 ...
- poj 1083 Moving Tables
题目 两种做法,开始用贪心做的,有种情况没考虑到,结果排序错了. 这个例子,感觉上有三个交点,以为是30,其实是20. 贪心代码: #include <iostream> #include ...
- 【POJ1083】 Moving Tables (并行的搬运)
BUPT2017 wintertraining(15) #6E 题意 房间1和2,3和4,...,399和400共用一节走廊,有q次从房间li到ri的搬运桌子,一次搬运10分钟.两个搬运如果走廊有重叠 ...
- POJ-1083 Moving Tables(imos算法)
这一题有两个陷阱: 给出的起始点可能小于终点 ,所以必须要加个判断,让第二个数大于第一个数 区间算的时候,一定是奇数到偶数,才能做到真正的区间全覆盖.所以如果第二个数是奇数,要加一变为偶数:第一个数为 ...
- 你听过算法也是可以贪心的吗?
点击"阅读原文"直接打开[北京站 | GPU CUDA 进阶课程]报名链接 贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加 ...
最新文章
- c++内存中字节对齐问题详解
- 使用JavaScript遍历本地文件夹的文件
- vtigerCrm 目录结构(整理中)
- 【华为云技术分享】Linux内核模块依赖图绘制(2)
- python中的OrderedDict
- 2d游戏中关于碰撞以及渲染层级关系
- 随手记_英语_50大英文经典句/美句
- 如何完全卸载MySQL
- 汇编语言--DOSBox 0.74的安装与简单使用
- 金蝶云星空之表单插件的开发
- fpga基础入门知识
- 强烈推荐一个有情怀的跨平台Redis可视化客户端工具:RedisViewer
- linux搭建tht框架,教程 中标麒麟linux硬盘安装图解
- Resend messages one by one
- 【应用随机过程】03. 马尔可夫链的状态
- 在VMWare虚拟机上安装CentOS 7
- e-a乘a的转置的秩_通用矩阵乘(GEMM)优化与卷积计算
- 用宝塔面板网站php变成静态,宝塔面板设置伪静态规则
- Winform GDI+ 制作连连看,五子棋等(等格子类小游戏 )
- matlab音乐合成报告,matlab音乐合成报告