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. P3376 【模板】网络最大流( Edmonds-krap、Dinic、ISAP 算法)

    P3376 [模板]网络最大流( Edmonds-krap.Dinic.ISAP 算法) 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S ...

  2. 【Java技术系列】爱情36技之Bug大战

    1. 鲁迅先生说:程序员,天不怕地不怕,就怕小虫儿爬呀爬,爬呀爬. 随着时间的推移,鲁迅先生又说:真正勇猛的程序员,敢于让虫子面对惨淡的虫生. 虫子在程序员心中是啥东西?虫子的学名为 Bug,是多少入 ...

  3. 三角函数在Three.js中的点的移动轨迹应用

    在学习2D文字的时候,看到官网有这样一个示例: https://threejs.org/examples/#css2d_label ![](https://img2018.cnblogs.com/bl ...

  4. Vue引用阿里图标库

    首先进入官网http://www.iconfont.cn/ 转载:https://blog.csdn.net/qq_34802010/article/details/81451278 选择图标库 在里 ...

  5. Shell:Day08.笔记

    函数:写一个代码块,用来重复调用的: 1.函数的写法格式 2.参数,在函数名后面直接加,即可:如果在外面  abc(){   函数体 $@  }  abc 1 2 3 4 5   :wq    a.s ...

  6. ssh配置文件最佳实践(伪)

    时间:2019-09-11 说明:以下配置是基于常用安全设置,并增加阿里云要求的安全参数而成 版本:第一版 # 1.监听相关 ## 指定ssh端口 Port 1314 ## 只监听网络协议 Addre ...

  7. Python高级特性-迭代器和生成器

    迭代器 Python中可迭代对象(iterable)通俗指可直接作用与For循环的数据对象,如Python中的集合数据类型,字符串(str),列表(list),元组(tuple),集合(set),字典 ...

  8. 理解class.forName() ---使用jdbc方式链接数据库时会经常看到这句代码

    目录(?)[-] 官方文档 类装载 两种装载方法的区别 不同的类装载器 是否实例化类 在jdbc链接数据库中的应用 资源   原文地址:http://yanwushu.sinaapp.com/clas ...

  9. 返回指定字符串位置的函数FIELD(S,S1,S2,...) 与 FIND_IN_SET(S1,S2) 函数

    FIELD(S,S1,S2,...)  与 FIND_IN_SET(S,S1) 函数  ------> 这2个函数都是返回指定字符串在源串中的出现的位置(皆是第一次出现的位置),但2个函数的参数 ...

  10. js操作svg整体缩放

    首先我们先创建一个svg整体布局,代码如下: <!DOCTYPE html> <html> <head> <title>js操作svg实现整体缩放< ...