`

PAT 1008. Elevator

    博客分类:
  • PAT
 
阅读更多

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

Output Specification:

For each test case, print the total time on a single line.

Sample Input:
3 2 3 1
Sample Output:
41

#include<stdio.h>
int floor[100];
int main(){
		int n;
        scanf("%d", &n);
		if(n==0) return 0;
		int i;
		int costTime = n * 5;
		for( i =0; i< n; i++){
			scanf("%d", &floor[i]);
			if(i >= 1){
				if(floor[i] > floor[i-1]) costTime += (floor[i]-floor[i-1])*6;
				else if(floor[i] < floor[i-1]) costTime += (floor[i-1]-floor[i])*4;
			}
			else{
				costTime += floor[i]*6;
			}
		}
		printf("%d\n", costTime);
        return 0;
}

 

分享到:
评论

相关推荐

    elevator.exe

    elevator.exe

    返回顶部按钮elevator.js.zip

    elevator.js 是一个 "back to top" 按钮,即点击 "back to top" 按钮即可缓慢的返回网页顶部。  示例: [removed] // Elevator script included...elevator.elevate(); [removed] 标签:elevator

    Simulator.Elevator:模拟建筑物中电梯的使用

    在这个名为"Simulator.Elevator"的项目中,我们将探讨如何使用JavaScript来实现一个电梯模拟器。 JavaScript是一种广泛用于Web开发的编程语言,它不仅可以用于前端交互,也可以在Node.js环境中用于后端开发。在这个...

    java-elevator.rar_elevator_java elevator_java-elevator

    在这个“java-elevator.rar_elevator_java elevator_java-elevator”项目中,开发者通过Java语言来实现了一个电梯模拟系统,旨在帮助学习者理解和实践这些关键的Java特性。 首先,我们要理解电梯的基本工作原理:...

    my_ELEVATOR.rar_elevator_my_ELEVATOR_双电梯_电梯 双_电梯模拟界面

    本文将深入探讨一个名为"my_ELEVATOR.rar_elevator_my_ELEVATOR_双电梯_电梯 双_电梯模拟界面"的项目,这是一个专为电梯控制系统设计的双电梯模拟软件。这个软件的开发者通过交互式的按键界面和状态栏,成功地模拟了...

    ElevatorSimulation.zip_elevator software_电梯客流_电梯群控系统_电梯群调度_评估软件

    电梯群控系统服务质量和运行效能评估软件设计与实现 建立了电梯客流到达模型,然后建立了6种电梯群调度模型

    赵昊伟_C语言学习电梯程序Elevator

    1. `Elevator.cpp` - 这是主要的源代码文件,很可能包含了电梯系统的主要逻辑,包括电梯对象的定义、动作的实现(如上升、下降、开门、关门)以及与乘客请求交互的函数。 2. `StdAfx.cpp` - 这通常是Visual Studio...

    Elevator Evacuation in Emergency Situations.pdf

    algorithm that has been designed by ThyssenKrupp Elevator Company for the express purpose of evacuating mid to high rise buildings and demonstrates the reduced time of egress as opposed to traditional...

    159-Elevator Display_elevator_bascomavr_

    标题中的“159-Elevator Display_elevator_bascomavr_”表明这是一个关于电梯显示系统的项目,使用了Bascom AVR编程语言。Bascom AVR是一种基于Basic语法的微控制器编程工具,专为AVR系列微处理器设计,常用于嵌入式...

    java for elevator

    this is the java code for elevator which can be applied on elevator operation.

    elevator_sim.pro.user

    elevator_sim.pro.user

    dianti.rar_elevator_电梯

    在本项目"电梯.rar_elevator_电梯"中,我们关注的是一个针对六层楼电梯的控制程序,主要使用C++语言编写。这个程序旨在模拟真实世界中的电梯操作,包括接收乘客请求、调度电梯移动以及在各个楼层停靠。 1. **电梯...

    Elevator.dsp

    Elevator.dsp

    vhdl.rar_elevator vhdl code_电梯控制器

    在这个“vhdl.rar_elevator vhdl code_电梯控制器”压缩包中,我们主要探讨的是如何使用VHDL来设计一个电梯控制系统。 电梯控制器的核心在于实现对电梯运动的有效管理和调度,确保乘客的安全和高效运行。在VHDL代码...

    EE.rar_elevator_汇编电梯_电梯ee02_电梯汇编

    本文将深入探讨"EE.rar_elevator_汇编电梯_电梯ee02_电梯汇编"这个压缩包中的知识点,主要围绕电梯的汇编语言编程进行讨论。 首先,汇编语言是计算机编程的基础语言之一,它直接对应于机器指令,程序员通过汇编语言...

    lift.rar_elevator stm32_stm32 电梯_stm32 电梯_升降_电梯程序STM32

    STM32 mini开发板,实现触摸电梯升降小程序

    Elevator.c

    简单电梯模拟程序,一个.c文件,版权所有,请于24小时内删除,勿用于商业用途

    elevator.rar

    《Cocos2d-x引擎下的电梯模拟调度程序详解》 在计算机科学中,电梯调度算法是一种典型的多任务处理问题,其目标是优化电梯系统的效率,确保乘客能够快速、有效地达到目的地。本文将深入探讨一个使用Cocos2d-x游戏...

Global site tag (gtag.js) - Google Analytics