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 ...
 
随机推荐
- centos 7.3安装教程
			
进入安装初始化界面 等待检查完就可以进入安装了,不想等待的按ESC退出,没关系的 语言这里我们推荐使用英文: 然后点击Continue继续 选择-系统SYSTEM-安装位置INSTALLTION DE ...
 - c++-string-1
			
解答注意: 我写的时候考虑了: 1) " my"(设置flag,为true时表示上一个是非空格字符) 2) "hello John"(最后不是空格结尾, ...
 - 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 F题
			
The Heaviest Non-decreasing Subsequence Problem 解题心得 这个题就是一个简单的动态规划,非递减最长子序列的改版(加一个权重),只要把权重为5的改成5个权 ...
 - Oracle中创建触发器示例及注意事项
			
1.oracle 中创建触发器示例 CREATE TABLE "CONCEPT"."FREQUENCYMODIFYLOG" ( "FREQUENCYI ...
 - idea导入jdk源码查看(xjl456852原创)
			
idea添加了jdk环境后,却无法查看jdk源码,只能通过idea自带的反编译查看,看起来有些不爽. 下面来说一下如何设置,导入jdk源码,查看时通过源码查看jdk. 1.点击菜单 File -> ...
 - unittest编写Web测试用例
			
案例:百度搜索关键词:“unittest” test_baidu.py: from selenium import webdriver from time import sleep import un ...
 - Jmeter接口测试-简单分析结果数、聚合报告以及图形结果(二)
			
简单分析结果数.聚合报告以及图形结果 结果树 取样器结果:返回值报200,表示执行接口调试成功 请求:发送的数据 响应数据:返回的数据 Thread Name:线程组名称 Sample Start: ...
 - wlan
			
一.概述 CSMA/CD --->以太网介质 CSMA/CA------->无线介质 IEEE----->802.11 a b g e f h i j 分类 ...
 - [转]常见linux命令用法介绍
			
su switch user 用途:用于用户之间的切换 格式: su - USERNAME切换用户后,同时切换到新用户的工作环境中 su USERNAME切换用户后,不改变原用户的工作目录,及其他环境 ...
 - JSON.parse与eval区别
			
两种方式都可以解析json字符串,不过有时候JSON.parse解析会失败,失败原因有多种,下面会指出一种. JSON.parse()解析json格式的数据,会对要解析的字符串进行格式检查,如果格式不 ...