POJ 1083 && HDU 1050 Moving Tables (贪心)
Moving Tables
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20302 Accepted Submission(s): 6889

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.
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.
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
解题思路:贪心。考虑每次的最优解,则对面的两房间共有它们所相应的区域,每次交错,都会产生一次冲突,就代表他们不能在同一次搬运,考虑到多次转移的交错的区域,最大交错的次数就代表了最小的搬运次数。
AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std; int room[205]; int main(){
// freopen("in.txt", "r", stdin);
int t, n, x, y;
scanf("%d", &t);
while(t--){
memset(room, 0, sizeof(room));
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d%d", &x, &y);
if(x > y) swap(x, y); //防止起始房间大于终止房间
for(int i=(x+1)/2; i<=(y+1)/2; i++){
room[i] ++; //相应区域的交错次数添加
}
}
int ans = 0;
for(int i=1; i<=201; i++){
if(ans < room[i]) ans = room[i];
}
printf("%d\n", ans*10);
}
return 0;
}
POJ 1083 && HDU 1050 Moving Tables (贪心)的更多相关文章
- --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 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- 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 ...
- HDU 1050 Moving Tables (贪心)
题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...
- hdu 1050 Moving Tables(迷之贪心...)
题意:有400间房间按题目中图片所给的方式排列,然后给出要移动的n张桌子所要移动的范围,每张桌子要移动的范围不能出现重叠的区域:问最少要多少次才能移动完所有的桌子. 题解思路:把题目转换下,就是有n个 ...
- hdu 1050 Moving Tables_贪心
题意:你搬n个桌子,桌子从一个地方搬到另一个地方,走廊只允许同时一个桌子通过,教室分布在两边,奇数在一边,偶数在一边,当桌子不冲突时可以同时搬运,冲突时要等别的那个桌子搬完再搬. 思路:因为奇数桌子在 ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- verilog behavioral modeling--procedural continous assignment(不用)
assign / deassgin force /release the procedural continuous assignments(using keywords assign and for ...
- git2--常用命令
Git 命令详解及常用命令 Git作为常用的版本控制工具,多了解一些命令,将能省去很多时间,下面这张图是比较好的一张,贴出了看一下: 关于git,首先需要了解几个名词,如下: ? 1 2 3 4 Wo ...
- 二丶人生苦短,我用python【第二篇】
1 编码 python解释器在加载 .py 文件中的代码时,对内容默认进行ascill编码,因此存在中文会报错,所以需要告诉python解释器,用什么编码来执行源代码.) ASCII码,主要用于显示现 ...
- jmeter结果分析详解
Jmeter测试报表相关参数说明 采用Jmeter测试工具对web系统作的负载测试,得出的响应报表,数据比较难懂,现作一具体说明.以下是在一次具体负载测试中得出的具体数值,测试线程设置情况为:线程数: ...
- Mac 生成public_key
1.首先查看是否已经生成过public_key 打开终端查看是否已经存在SSH密钥:cd ~/.ssh 输出:No such file or directory表示没有 2.生成public_key ...
- 【LeetCode】String Without AAA or BBB(不含 AAA 或 BBB 的字符串)
这道题是LeetCode里的第984道题. 题目要求: 给定两个整数 A 和 B,返回任意字符串 S,要求满足: S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母: ...
- Centos7 编译安装python3
step1:preparation $ yum install yum-utils make wget gcc $yum-builddep python step2:download $ wget h ...
- .NET重构(四):窗体继承+模板方法,完美实现组合查询
导读:在机房重构中,有好些个查询都是大同小异,最为显著的就是组合查询了.怎样给自己省事儿,相同的东西能不能重复利用,就成了一个现实的问题.第一遍做机房的时候,使用的更多的是:复制+粘贴.学习了设计模式 ...
- 刷题总结——路径(ssoi)
题目: 题目背景 CF 57D 题目描述 小美今天和她的好朋友在玩捉迷藏游戏.地图可以抽象成一张 n*m 的图,地图上有一些障碍.但这些障碍有一些性质:1:每个障碍周围 8 个格子是没有障碍的.2:每 ...
- 算法复习——树链剖分模板(bzoj1036)
题目: 题目背景 ZJOI2008 DAY1 T4 题目描述 一棵树上有 n 个节点,编号分别为 1 到 n ,每个节点都有一个权值 w .我们将以下面的形式来要求你对这棵树完成一些操作:I.CHAN ...