ACM--移动桌子--贪心--HDOJ 1050--Moving Tables
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
- 3
- 4
- 10 20
- 30 40
- 50 60
- 70 80
- 2
- 1 3
- 2 200
- 3
- 10 100
- 20 80
- 30 50
- 10
- 20
- 30
- 题意:在一个狭窄的走廊里将桌子从一个房间移动到另一个房间,走廊的宽度只能允许一个桌子通过。给出t,
表示有t组测试数据。再给出n,表示要移动n个桌子。n下面有n行,每行两个数字,表示将桌子从a房间
移到b房间。走廊的分布图如一图所示,每移动一个桌子到达目的地房间需要花10分钟,问移动n个桌子
所需要的时间。
分析:
若移动多个桌子时,所需要经过的走廊没有重合处,即可以同时移动。若有一段走廊有m个桌子都
要经过,一次只能经过一个桌子,则需要m*10的时间移动桌子。设一个数组,下标值即为房间号。
桌子经过房间时,该房间号为下标对应的数组值即加10。最后找到最大的数组值,即为移动完桌子
需要的最短时间。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int t,n,repeat[],i,from,to,temp;//repeat存放重复次数,from为出发点,to为目的地
- scanf("%d",&t);
- while (t--)
- {
- scanf("%d",&n);
- memset(repeat,,sizeof(repeat));
- while (n--)
- {
- scanf("%d %d",&from,&to);
- if (from>to)//可能出发位置比目的地房间大。无论大小,我们都可以看做从小的房间移动到大的房间
- {
- temp=to;
- to=from;
- from=temp;
- }
- if (from%==)//考虑实际情况,出发房间为偶数时减一,可参照题中给出的图
- {
- from=from-;
- }
- if (to%==)//目的地房间为奇数时加一
- {
- to+=;
- }
- for (i=from;i<=to;i++)
- {
- repeat[i]+=;
- }
- }
- printf("%d\n",*max_element(repeat,repeat+));//STL中寻找数列最大值函数
- }
- return ;
- }
ACM--移动桌子--贪心--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 ...
- Hdoj 1050.Moving Tables 题解
Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...
- POJ 1083 && HDU 1050 Moving Tables (贪心)
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 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 AC code: #include<stdio.h> #include<str ...
- HDU 1050 Moving Tables (贪心)
题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...
- hdu 1050 Moving Tables(迷之贪心...)
题意:有400间房间按题目中图片所给的方式排列,然后给出要移动的n张桌子所要移动的范围,每张桌子要移动的范围不能出现重叠的区域:问最少要多少次才能移动完所有的桌子. 题解思路:把题目转换下,就是有n个 ...
随机推荐
- HTML学习---基础知识学习
1.1. HTML 1.为什么要有HTML? "Hello" "<h1>Hello</h1>" - 浏览器渲染时使用一套HTML规则, ...
- Asp.Net MVC 开发技巧(一)
开发程序时的流程: 1.设计数据模型. 数据模型最为重要,不仅关系到数据的存储,同时程序的可扩展性,效率也受影响,甚至决定开发工作量.所以要极其认真的设计数据库的表和相关字段. 建完基本的数据模型后, ...
- winform中webBrowser模拟网页操作中遇到的问题
我们通过网页上传一些特殊数据的时候,由于必填项众多,数量量大的时候,会发现工作相当繁琐,前段时间做了一个winform内嵌webBrowser模拟网页上传文档的小工具,发现了许多问题,总结一下: 先说 ...
- TCP/IP 协议图--计算机网络体系结构分层
计算机网络体系结构分层 计算机网络体系结构分层 不难看出,TCP/IP 与 OSI 在分层模块上稍有区别.OSI 参考模型注重“通信协议必要的功能是什么”,而 TCP/IP 则更强调“在计算机上实 ...
- SQL简单基础(2)
查询功能是SQL语句最重要的功能,查询操作也是数据库系统最常用的操作.学习SQL查询语句,首先要弄清楚的是查询语句用到的关键字以及查询语句的执行顺序.SQL语言的一个特点在于,它是一种声明式语句,执行 ...
- 随手练——S(n)=O(1),判断一个链表是否为“回文”
方法一:T(n)=O(n),S(n)=O(n) 走完一遍链表,每个值入栈,之后再走一遍链表,和每次弹出的栈顶进行比较. 核心: LNode *p = l->next; while (p) { s ...
- 通过css使文字有渐变的效果
<style> .color{ background-image: -webkit-gradient(linear, left center, right center, from(rgb ...
- Java8 Stream()关于在所有用户的所有上传记录中,找出每个用户最新上传记录
原创文章:转载请标明出处 https://www.cnblogs.com/yunqing/p/9504196.html 首先分析相当于如下,在所有的猫中,每个名字的猫都保留年龄最小的一个 import ...
- Qt中QScrollArea类的简单使用心得
平台:windows 64位 Qt版本:5.5.1 MinGW 32bit 根据自己目前的需求简单说下怎么在QScrollArea滚动窗口中实现多个控件的滚动显示,先看看最 ...
- 递归根据父ID 找所有子类ID
function getinfo($pid){ $str = ''; $row = M('user')->where(array('pid'=>$pid))->select(); i ...