1. 程式人生 > >HDU-1008-Elevator(Java版本+簡單模擬+噁心水果)

HDU-1008-Elevator(Java版本+簡單模擬+噁心水果)

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
[Submit][Status][Web Board]

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

HINT

Source