1. 程式人生 > >【杭電-oj】-1008-Elevator(電梯)

【杭電-oj】-1008-Elevator(電梯)

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
#include<stdio.h>
int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        int y=0;
        int a[111];
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        
        for(int i=1;i<=n;i++)
        {
            a[0]=0; 
            if(a[i]>a[i-1])
            {
                y=y+6*(a[i]-a[i-1])+5;
            }
            else
            {
                y=y+4*(a[i-1]-a[i])+5;
            }
        }
        printf("%d\n",y);
    }
    return 0;
}


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

相關推薦

-oj-1008-Elevator電梯

Problem Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The num

-oj-1865-1sting大數斐波那契數列

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5021    Accepted Submiss

-oj -1060-Leftmost Digit輸出n的n次方最左邊數

Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input The input contains several test

-oj-1064-Financial Management財務管理

Problem Description Larry graduated this year and finally has a job. He’s making a lot of money, but somehow never seems to have enough

OJ2032 楊輝三角

Problem Description 還記得中學時候學過的楊輝三角嗎?具體的定義這裡不再描述,你可以參考以下的圖形: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5

-oj-2008-數值統計

Problem Description 統計給定的n個數中,負數、零和正數的個數。 Input 輸入資料有多組,每組佔一行,每行的第一個數是整數n(n<100),表示需要統計的數值的

-oj-2076-夾角有多大

Problem Description 時間過的好快,一個學期就這麼的過去了,xhd在傻傻的看著表,出於對資料的渴望,突然他想知道這個表的時針和分針的夾角是多少。現在xhd知道的只有時間,請你幫

-oj-2012-素數判定

Problem Description 對於表示式n^2+n+41,當n在(x,y)範圍內取整數值時(包括x,y)(-39<=x<y<=50),判定該表示式的值是否都為素數。

oj2546

飯卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20176    Accepted Submissio

oj1280

前m大的數 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15329    Accepted Submis

oj2021發工資咯:

發工資咯:) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 51230    Accepted Submis

OJ——1198 Farm Irrigation 搜尋2

題目: Farm Irrigation Problem Description Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divi

笨方法學PAT1008 Elevator20 分

一、題目 The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at wh

PAT甲級1008 Elevator 20 分

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 flo

oj1599find the mincost route無向圖最小環

           find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s

1285確定比賽名次

                                                  確定比賽名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe

1878歐拉回路

歐拉回路 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descr

oj1159Common Subsequence

                             Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total

2035人見人愛A^B

#include<stdio.h> __int64 quick(int a,int b) { __int64 ans=1,base=a; __int64 t=0;

Number Sequence -1005 附題+詳解

/*Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others