Hdu-1008-elevator (Java version + simple simulation + disgusting fruit)

Source: Internet
Author: User

ElevatorTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 50645 Accepted Submission (s): 27932


Problem DescriptionThe Highest building in We City have only one elevator. A request list is made to with N positive numbers. The numbers denote at which floors the elevator would stop, in specified order. It costs 6 seconds to move the elevator-one floor, and 4 seconds to move-down-one floor. The elevator would stay for 5 seconds on each stop.

For a given request list, you is 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 having to return to the ground floor when the requests was Fu Lfilled.

Inputthere is multiple test cases. Each case contains a positive an integer n, followed by N positive numbers. All the numbers in the input is less than 100. A test Case with N = 0 denotes the end of input. This test is a not-to-be processed.

Outputprint the total time, on a, on a, a, and each test case.

Sample Input
1 23 2) 3 10

Sample Output
1741

Authorzheng, Jianqiang
SourceZJCPC2004
recommendjgshining | We have carefully selected several similar problems for you:1009 1021 1003 1108 1019

In fact, according to the truth, the problem is simple can not be a simple simulation elevator! But our general thinking is not like this, we will find it up the highest floor, and then calculate the time he spent on the rise, and the time of the fall, and then find out the time he stayed. Add up! Then the disgusting place of the problem is manifested! For test data: 3 2 3 141 stop at each level, it means stopping at each level of the 0->2->3->1 in the 2,3,1 layer, that is! 3->1 the 2 floor of this place is nonstop, and then pay attention to continuously enter the same floor, still have to stop, that is, input 2 1 1 The answer is 16 seconds instead of 11 seconds.
And the elevator will not take the shortest way ... It will only follow the input order, rise or fall, a simple simulation can be ac! fortunately before the school OJ did this problem .... Or you have to spit blood! (school OJ Chinese title below!!) )

Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {//TODO auto-generated Metho D stubscanner input = new Scanner (system.in), while (Input.hasnext ()) {int n = input.nextint (), if (n==0) Break;int begin=0, stop=0,sum=0;                Begin represents the floor where the elevator is located, and stop indicates the floor for which the lift is to be reached 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: The elevator came. Time limit: 1 Sec Memory Limit: MB
Submit: 176 Solved: 123
[Submit] [Status] [Web Board] Description

There is only one elevator in a high-rise building. Given an elevator to stay on the floor of the sequence (n non-negative integers), please calculate the elevator to complete this dwell sequence of how many seconds spent. It takes 6 seconds to set up an elevator, each on the next floor takes 4 seconds, and waits 5 seconds each time on the stay floor. Keep in mind that elevators always start from the No. 0 floor (basement) and no longer need to return to the basement.

Input

The input data contains multiple sets of test data. Each set of data is a row, containing a nonnegative natural number n, followed by n nonnegative integers (representing the sequence of floors to stay), which are less than 100. If n is 0, the input ends and no processing is required.

Output

For each set of test data, the total time (in seconds) that the output will take to complete the dwell sequence.

Sample Input1 2 3 1 5 4 3Sample Output174171HINT

Source

[Submit] [Status] [Web Board]


Hdu-1008-elevator (Java version + simple simulation + disgusting fruit)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.