ACM--移动桌子--贪心--HDOJ 1050--Moving Tables

杭电1000到1050 acm解题报告 http://acm.hdu.edu.cn/ 1102 1106 1108 1114 1142 1146 1150 杭电 acm的AC解题报告 立即下载


HDOJ题目地址:传送门

Moving Tables

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


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
 

题意:在一个狭窄的走廊里将桌子从一个房间移动到另一个房间,走廊的宽度只能允许一个桌子通过。给出t,

   表示有t组测试数据。再给出n,表示要移动n个桌子。n下面有n行,每行两个数字,表示将桌子从a房间

   移到b房间。走廊的分布图如一图所示,每移动一个桌子到达目的地房间需要花10分钟,问移动n个桌子

   所需要的时间。

解题思路:若移动多个桌子时,所需要经过的走廊没有重合处,即可以同时移动。若有一段走廊有m个桌子都

     要经过,一次只能经过一个桌子,则需要m*10的时间移动桌子。设一个数组,下标值即为房间号。

     桌子经过房间时,该房间号为下标对应的数组值即加10。最后找到最大的数组值,即为移动完桌子

     需要的最短时间。


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int t,n,count[410],i,start,end,k;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		memset(count,0,sizeof(count));
		while(n--){
			scanf("%d%d",&start,&end);
			//可能出发位置比目的地房间大。
			if(start>end){
                //无论大小,我们都可以看做从小的房间移动到大的房间
				k=start;
				start=end;
				end=k;
			}
			if(start%2==0)//考虑实际情况,出发房间为偶数是减一,可参照题中给出的图一
			   start-=1;
			if(end%2==1)//目的地房间为奇数时加一
			   end+=1;
			for(i=start;i<=end;++i)
			   count[i]+=10;
		}
		printf("%d\n",*max_element(count,count+400));//STL中寻找数列最大值函数
	}
	return 0;
}




参考博客:传送门

ISO 15118-20标准深度解读【精简篇】 ISO 15118-2 是开创者,它解决了“如何让电动汽车充电像给手机充电一样简单(即插即用且自动付费)”的问题,为行业奠定了基础。 ISO 15118-20 是革新者,它站在前者的肩膀上,回答了一个更宏大的问题:“如何让电动汽车深度融入未来的能源系统和智慧城市?” 它不仅是充电协议,更是一个车网互动的综合能源管理协议。简单来说,ISO 15118-2 是关于“如何充电”,而 ISO 15118-20 是关于“如何智慧地使用和管理电动汽车这块大电池”。 阅读详情

相关推荐

EBSD数据转ABAQUS的inp文件实操指南

晶体塑性有限元模拟中,如何将材料微观组织表征数据转化为可计算的有限元模型,是连接实验与仿真的关键环节。EBSD技术能够获取材料表面的晶体取向、晶粒形貌和晶界分布信息,但这类数据需要经过格式解析、欧拉角转换、网格生成等步骤,才能被ABAQUS等有限元软件读取。通过将扫描点坐标映射为节点、按像素邻域生成单元,并将Bunge约定欧拉角变换为局部坐标系方向余弦,用户可以准确构建包含真实微观结构的inp文件模型。这一流程广泛应用于金属材料形变、织构演化及应力集中分析等研究场景,有效提升仿真结果与实验的一致性。围绕数据

weixin_42509513的博客 320

hdoj1050 Moving Tables(贪心算法?)

贪心算法详解的入口http://blog.csdn.net/effective_coder/article/details/8736718 思路:给了n对相互之间要进行桌子移动的房间对,如果区间发生重叠,桌子的移动不能同时进行。题目要我们求把桌子移动好的最短时间。 我们必须认清一个必然事件,无论我们怎么安排次序,只要最后把桌子都移好,所经过的路径都是一致的,也就是说某个房间被桌子经过 的次数

CqZtw的博客 568

基于阻抗控制的工业机器人轨迹跟踪系统 Simulink/Simscape 仿真

  本文是对文献 [1] 的复现。 关于阻抗控制   阻抗控制的提出可以追溯到 1984 年,Neville Hogan 在 American Control Conference 发表的 Impedance Control:An Approach to Manipulation ,次年,Hogan N. 又在 Journal of Dynamic Systems Measurement and Control-transactions of The Asme 发表了阻抗控制经典三部曲 —— Imped.

-贝塔- 的博客 2万+

HDOJ-1050 Moving Tables (贪心算法)

题目:HDOJ-1050 题目描述: 南北各200个房间,编号1~400,从一个房间搬桌子到另一个房间都要10分钟,路径有重合部分(包括端点)的不能同时搬,求最少需要多少时间把要搬的桌子搬完。 思路: 一开始就想着排序,区间不相交,依次模拟着来算时间,但是这样很麻烦。 看了下别人的题解,完美地把问题化简了,一步到位。 因为如果有某个区间被n个搬桌子的任务覆盖了,那么无论如何都必须要n次才能搬完,...

Plus Ultra! 497

如何用ISBN API快速获取图书信息?Python实战教程(附完整代码)

本文是一篇Python实战教程,详细介绍了如何利用ISBN API高效获取图书元数据。内容涵盖从API服务选择、密钥管理,到使用requests库构建健壮的请求模块,并利用Pydantic进行数据验证与解析。教程还提供了批量查询、缓存优化及集成到Flask Web应用等高级技巧,帮助开发者快速实现图书信息的自动化获取与处理。

p8q9r0的博客 459

MATLAB安装

Matlab 2016a 安装包及破解教程百度云分享链接: 链接:https://pan.baidu.com/s/1i6BgD8p       密码:17gg   Matlab安装教程: 1、下载文件,得到R2016a_win64.part1.rar、R2016a_win64.part2.rar两部分安装文件和Matlab 2016a Win64 Crack破解文件。 2、解压安装文件(解...

qq_36734094的博客 17万+

HDOJ 1050 :Moving tables

题目大意 著名的ACM(高级计算机制造商)公司租用了一栋建筑的地板,其形状如下。楼沿走廊的北侧和南侧各有200间客房。最近,公司制定了一项改革计划。改革包括在房间之间移动很多桌子。因为走廊很窄,所有的桌子都很大,只有一张桌子能穿过走廊。需要一些计划来提高移动效率。经理想出了以下计划:将桌子从房间移到另一个房间可以在 10 分钟内完成。将桌子从 I 房间移到 j 房间时,使用 I 房间前面和 j 房间前面之间的走廊部分。因此,每10分钟,在两个房间之间移动几个不共享走廊的同一部分将同时进行。为了清楚说明,经

m0_61223040的博客 309

跨平台商品模型大解析:亚马逊 vs 阿里 vs 拼多多

本文深入探讨了亚马逊、阿里巴巴和拼多多三大电商平台的商品模型设计,分析了它们在变体关系、商品抽象层级和SKU定义等方面的异同。亚马逊模型以物流和变体为中心,强调全球仓配体系下的标准化管理;阿里模型采用多视角的弹性结构,适用于多类目、多品牌、多卖家环境;拼多多模型则结合平台标准化与商家个性化,适合短期促销和快速上新场景。文章还提供了实践建议,帮助自研电商平台或商品中台的开发者选择合适的商品结构,并强调了商品模型在电商系统中的核心作用。通过对比分析,本文旨在为读者提供商品建模的启发和参考。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 13万+

贪心算法———房间搬桌子

题目描述 著名的ACM(Advanced Computer Maker)公司租用了一层有400个房间的办公室,结构如表1所示。 表1 ACM公司办公楼室示意图 房间1 房间3 房间5 … ...

笼中鸟 2719

BLDC控制实验:方波、霍尔、开环、定速、正转

本文记录博主学习BLDC控制软件的过程。 文章目录1 概述2 软件架构及工具链2.1 软件架构2.2 工具链3 底层代码生成3.1 时钟配置3.2 按键输入配置 1 概述 本文是博主第一次做BLDC控制实验,目的仅仅是写代码让BLDC转起来,而暂时不考虑其他复杂的需求。 控制的方法是比较简单的六步换相法。利用电机内部的霍尔传感器,通过参考电机厂家给出的二二导通换相表,生成方波来控制电机。第一次实验为了简化需求,只考虑开环、定速、正转的情况: 开环:不考虑速度反馈,直接给PWM让电机转起来; 定速:不考虑速

u013288925的博客 1万+

FPGA实现DDR接口

verilog// DDR2控制器状态机// 初始化序列// 发出初始化命令endendendend// 自动预充电end// 其他状态...endcaseendend。

whm128的博客 1012

hdoj 1050

#include<bits/stdc++.h> using namespace std; #define man 210 int main(void) { int n,r[man<<1],c[man]; int T,s,t; scanf("%d",&T); for(int i=1;i<=200;i++) { r[i<<1]=i; r[(i<<1)-1]=i; } while(T--) { memset(c,0,size

rch2020082203的博客 182

连接参数详解:Connection Interval, Slave Latency, Supervision Timeout 的协同与调优实战

在低功耗蓝牙(BLE)开发与调试中,Connection Interval(连接间隔)、Slave Latency(从机延迟) 和 Supervision Timeout(监督超时) 是三个核心参数。它们不仅直接影响设备的通信性能、功耗表现和连接稳定性,更是各类技术面试与认证考试的高频考点。本文将从基础概念出发,深入剖析三者的协同机制,结合历年真题解析考点与解题思路,并通过实战案例演示调优方法,快速掌握这一核心知识点。

byte轻骑兵的技术小窝 2768

HDOJ_1050 Moving Tables 解题报告

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 sid

xxm137164869的专栏 2024

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDOJ Moving Tables JAVA 1050

贪心算法 对于这个题,一开始走的是模拟的思想,建立了相应的类进行模拟,不仅慢,复杂,而且结果wrong(不知道为什么) 后来改进了思想才轻松AC的: 主要是看每个房间出现过几次。因为一个房间每次只能出现一次,所以出现的最多的次数就是答案。 package _1050; import java.util.Arrays; import java.util.Scanner; publ

董公子的博客 440

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

HDOJ 1050 Moving Tables(经典贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24553    Accepted Submission(s): 8116 Problem Description The famous

Chunzhen的博客 2196

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HDOJ 1050 Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26508    Accepted Submission(s): 8775 Problem Description The famous

RaAlGhul的博客 439

HDU 1050 Moving Tables

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.

weymin 415

hdoj 1050 Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24631    Accepted Submission(s): 8144 Problem Description The famous ACM

longge33445的博客 730

Hdoj 1050.Moving Tables 题解

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 s...

weixin_30394251的博客 89

hdoj 1050 Moving Tables && nyoj 220 推桌子 (经典贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29660    Accepted Submission(s): 9712 Problem Description The famous ACM

R 376

HDOJ 1050 Moving Tables(贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24356    Accepted Submission(s): 8064 Problem Description The famous ACM

阿金的ACM 444

hdu1050 Moving Tables (贪心求最大重叠数)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24989    Accepted Submission(s): 8265 Problem Description The f

把复杂的事情简单描述 599

1083 -- Moving Tables

Moving Tables Time Limit:1000MS Memory Limit:10000K Total Submissions:32929 Accepted:11032 Description The famous ACM (Advanced Computer Maker) Company has rented ...

weixin_30902675的博客 158

hdoj 1050

//找出几个搬动区间的重叠部分重叠次数最多的次数即为整个搬动任务的最少搬动次数(可以同时) //房间是两侧的,注意处理奇偶性 #include using namespace std; int a[401]; int main(void) {     int T, s, e,t,n,max;     cin >> T;     while (T--)     {     

WuchangI的博客 374
上一篇: ACM--虫子爬井--模拟--HDOJ 1049--Climbing Worm--水
下一篇: ACM--过沼泽--模拟--HDOJ 5477--A Sweet Journey
学霸的一天
博客等级 码龄12年 182粉丝 243原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值