Cdzsc_2015 new Winter Holiday (1)--Basic B

Source: Internet
Author: User

Description

The 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.

Input

There 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.

Output

Print the total time, on a, on a, a, single, and test case.

Sample Input

1 23 2) 3 10

Sample Output

1741
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;structdangchi{Charstr[ -]; intsum;};intMain () {#ifdef cdzsc_offline freopen ("In.txt","R", stdin);#endif    intn,a,b,sum;  while(SCANF ("%d", &n) &&n!=0) {b=0, sum=0;  while(n--) {scanf ("%d",&a); if(a>b) {sum+ = (A-B) *6+5; b=A; }            Else if(a<b) {sum+ = (b-a) *4+5; b=A; }            Else{sum+=5; }} printf ("%d\n", sum); }    return 0;}
View Code

Cdzsc_2015 new Winter Holiday (1)--Basic B

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.