前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PAT 1008 Elevator

PAT 1008 Elevator

作者头像
ShenduCC
发布2018-04-26 17:33:10
5560
发布2018-04-26 17:33:10
举报
文章被收录于专栏:算法修养算法修养

1008. Elevator (20)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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 Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

Output Specification:

For each test case, print the total time on a single line.

Sample Input:

代码语言:javascript
复制
3 2 3 1

Sample Output:

代码语言:javascript
复制
41
代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
int n;
int a[105];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int pos=0;
    int ans=0;
    a[0]=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>a[i-1])
            ans+=(a[i]-a[i-1])*6;
        else if(a[i]<a[i-1])
            ans+=(a[i-1]-a[i])*4;
        ans+=5;
    }
    printf("%d\n",ans);
    return 0;

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-05-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1008. Elevator (20)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档