Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45555    Accepted Submission(s): 14817


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

这个题真是迷了, 一开始想的就是每次能搬尽量多的桌子,这样就能最快搬完,所以按照区间的右端排的序。
其实这样不是最快的,第一次筛选确实是一次搬得桌子最多,但是还要保证的是进行得次数最少而不等同于每次搬得个数最多, 可能会导致后面次数变多,还要顾及后面的。
 
例如这组测试数据
Input

Output
 还在一个地方卡了一会儿, 走廊的相邻奇数和偶数房间是对门的,共享一段走廊,所以奇数被占用时候,对门的偶数也是被占用了的。
所以应该对区间进行处理

        data[i].s = (data[i].s+1)/2;       data[i].t = (data[i].t+1)/2;
#include <iostream>
#include <stdio.h>
#include <algorithm> using namespace std; struct dat
{
int s;
int t;
int visit;
} data[]; bool cmp(dat a, dat b)
{
return a.s<b.s; // return a.t<b.t 是错的
} int main()
{
int t, n; scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d%d",&data[i].s, &data[i].t);
if(data[i].s>data[i].t)
{
int temp = data[i].s;
data[i].s = data[i].t;
data[i].t = temp;
}
data[i].s = (data[i].s+)/;
data[i].t = (data[i].t+)/;
data[i].visit=;
//printf("%d%d\n",data[i].s,data[i].t);
} sort(data, data+n, cmp); int ans=, j, temp; for(int i=; i<n; i++)
{
if(!data[i].visit)
{
j=i+;
temp = i;
data[i].visit=;
while(j!=n)
{
if(!data[j].visit&&data[temp].t < data[j].s)
{
data[j].visit=;
temp=j;
}
j++;
}
ans++;
}
} printf("%d\n", ans*); }
return ;
}

另一种思路就是区间覆盖,找覆盖次数最大的点的覆盖次数。

hdu_1050 Moving Tables 贪心的更多相关文章

  1. Moving Tables(贪心或Dp POJ1083)

    Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28304   Accepted: 9446 De ...

  2. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  3. HDU1050(Moving Tables:贪心算法)

    解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...

  4. UVAlive 2326 Moving Tables(贪心 + 区间问题)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...

  5. --hdu 1050 Moving Tables(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...

  6. POJ 1083 &amp;&amp; HDU 1050 Moving Tables (贪心)

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. hdoj 1050 Moving Tables【贪心区间覆盖】

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. Moving Tables

    Moving Tables Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. 面试必备:详解Java I/O流,掌握这些就可以说精通了?

    @TOC Java IO概述 IO就是输入/输出.Java IO类库基于抽象基础类InputStream和OutputStream构建了一套I/O体系,主要解决从数据源读入数据和将数据写入到目的地问题 ...

  2. PTA数据结构与算法题目集(中文) 7-4

    PTA数据结构与算法题目集(中文)  7-4 是否同一颗二叉搜索树 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, ...

  3. Hadoop(十一):组合任务概述和格式

    组合任务概述 一些复杂的任务很难由一个MR处理完成,所以一般需要将其拆分成为多个简单的MR子任务来执行. MapReduce框架中对于这类的问题提供了几种方式进行任务执行流程的控制,主要包括以下几种方 ...

  4. Java第十八天,可变参数

    可变参数 1.使用前提 当一个方法的参数需要多个参数,并且这些参数的类型一致时,可以使用可变参数. 2.使用方法 定义方法时使用 3.定义格式 修饰符 返回值类型 方法名(参数类型...变量名){ } ...

  5. canvas压缩、裁切图片和格式转换的方法

    按照大小压缩图片,或者按照特定分辨率裁切图片,转为blob数据.自动处理ios中可能存在的照片偏差90°问题. 例如,获取300*300大小的头像,实现以下效果: 使用方式: <!-- 引入js ...

  6. Array(数组)对象-->slice() 方法

    1.定义和用法 slice()方法可提取字符串的某个部分,并以新的字符串返回被提取的部分. 语法: array.slice(start, end) 参数:start 开始元素的下标,截取内容包含该元素 ...

  7. hadoop(十一)HDFS简介和常用命令介绍

    HDFS背景 随着数据量的增大,在一个操作系统中内存不了了,就需要分配到操作系统的的管理磁盘中,但是不方便管理者维护,迫切需要一种系统来管理多态机器上的文件,这就是分布式文件管理系统. HDFS的概念 ...

  8. Win安装docker

    Windows Docker 安装 win7.win8 系统 win7.win8 等需要利用 docker toolbox 来安装,国内可以使用阿里云的镜像来下载,下载地址:http://mirror ...

  9. 数据结构和算法(Golang实现)(20)排序算法-选择排序

    选择排序 选择排序,一般我们指的是简单选择排序,也可以叫直接选择排序,它不像冒泡排序一样相邻地交换元素,而是通过选择最小的元素,每轮迭代只需交换一次.虽然交换次数比冒泡少很多,但效率和冒泡排序一样的糟 ...

  10. webWMS开发过程记录(三)- 需求分析(略)

    行业:汽车零部件制造 大方向:非唯一码,需有一套简单.易用.受控的误操作撤回机制 现状(略) 目标(略) 注:由于项目是自己根据以往经验,自己开发的,且开发时间不固定,故需求分析暂略,我会把工作重点放 ...