HDU-1008-Elevator(Java版本+簡單模擬+噁心水果)
阿新 • • 發佈:2019-02-14
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:
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 MBSubmit: 176 Solved: 123
[Submit][Status][Web Board]
Description
某高層大廈僅有一座電梯。給定一個電梯要停留樓層的序列(N個非負整數),請你算出電梯完成這個停留序列共花費多少秒。設電梯每上一層樓需要6秒,每下一層需要4秒,每次在停留樓層需要等待5秒。請記住,電梯總是從第0層(地下室)開始執行,並且再也不需要返回地下室了。
Input
輸入資料包含多組測試資料。每組資料為一行,包含一個非負自然數N,然後跟著N個非負整數(表示要停留的樓層序列),這些整數都小於100。若N為0,則輸入結束,不需要進行處理。
Output
對於每組測試資料,輸出完成該停留序列需要花費的總時間(秒數)。