Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50645 Accepted Submission(s): 27932
Problem Description
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 2 3 2 3 1 0
Sample Output
17 41
Author
ZHENG, Jianqiang
Source
Recommend
JGShining | We have carefully selected several similar problems for you: 1009 1021 1003 1108 1019
其实按道理来说,这题是简单的不能再简单的模拟电梯!可是我们大家一般的思路不是这样的,
我们会求出它上升最高的楼层,然后算出他上升用的时间,和下降用的时间,然后求出他停留
的时间.再相加!然后这题恶心之处体现了!
对于测试数据:
3 2 3 1
41
每层停一下,是指在 0->2->3->1在2,3,1层每层停一下,就是说!3->1这个地方的2层是不停,然
后注意连续输入相同楼层,照样得停,就是输入 2 1 1 答案是16秒而不是11秒.
并且电梯不会走最短路经的方法...它只会按照输入顺序,上升或者下降,简单模拟一下就可以ac!
还好以前在学校oj做过这题.......不然非得吐血!(学校oj中文题在下面!!)
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); while(input.hasNext()) { int n = input.nextInt(); if(n==0) break; int begin=0,stop=0,sum=0; //begin表示前面电梯所在的楼层,stop表示电梯要达到的楼层 for(int i=0;i<n;i++) { stop = input.nextInt(); if(stop>begin) { sum+=(stop-begin)*6+5; } else { sum+=(begin-stop)*4+5; } begin = stop; } System.out.println(sum); } } }
1419: 电梯来了
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 176 Solved: 123
Description
某高层大厦仅有一座电梯。给定一个电梯要停留楼层的序列(N个非负整数),请你算出电梯完成这个停留序列共花费多少秒。设电梯每上一层楼需要6秒,每下一层需要4秒,每次在停留楼层需要等待5秒。请记住,电梯总是从第0层(地下室)开始运行,并且再也不需要返回地下室了。
Input
输入数据包含多组测试数据。每组数据为一行,包含一个非负自然数N,然后跟着N个非负整数(表示要停留的楼层序列),这些整数都小于100。若N为0,则输入结束,不需要进行处理。
Output
对于每组测试数据,输出完成该停留序列需要花费的总时间(秒数)。
Sample Input
1 23 2 3 15 1 5 4 3 10
Sample Output
174171