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:

3 2 3 1

Sample Output:

41

思路:模拟就完事儿,每上一层就+6,每下一层+4,每次再额外+5停留时间,增加一个t记录上次的楼层,判断是上升还是下降。
 #include <stdio.h>
int main()
{
int n,x;
while(scanf("%d",&n)!=EOF){
int sum=;
int t=;
for(int i=;i<n;i++){
scanf("%d",&x);
if(x>t){
sum+=(x-t)*;
t=x;
}else{
sum+=(t-x)*;
t=x;
}
sum+=;
}
printf("%d\n",sum);
}
return ;
}

PAT (Advanced Level) Practice 1008 Elevator (20 分) (模拟)的更多相关文章

  1. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  2. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  3. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  4. 【PAT Advanced Level】1008. Elevator (20)

    没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...

  5. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  6. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  7. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  8. PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

  9. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...

随机推荐

  1. [WPF 自定义控件]在MenuItem上使用RadioButton

    1. 需求 上图这种包含多选(CheckBox)和单选(RadioButton)的菜单十分常见,可是在WPF中只提供了多选的MenuItem.顺便一提,要使MenuItem可以多选,只需要将MenuI ...

  2. Flutter Widgets 之 InkWell 和 Ink

    注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 InkWell InkWell组件在用户点击时出现&quo ...

  3. codewars--js--Simple string expansion+ repeat(),includes()方法

    问题描述: Consider the following expansion: solve("3(ab)") = "ababab" -- "ab&qu ...

  4. 传智播客C++视频学习笔记(5)

    #include <iostream> using namespace std; void swapInt(int& a, int& b) { int temp = a; ...

  5. 【HDU - 1176 】免费馅饼 (逆dp)

    免费馅饼  Descriptions: 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁 ...

  6. HTML块级、行级元素,特殊字符,嵌套规则

    如果介绍HTML网页基本标签的嵌套规则,首先要说的就是元素的分类.元素可以划分为块级元素和行级元素,块级元素是什么?它可以独占一行,可以设置宽高度,默认是100%:行级元素与之相反,它的内容决定它的宽 ...

  7. nginx基础(二)

    二.nginx基础配置 (1)错误指向一个页面 http状态指向指定访问页面,在 /etc/nginx/conf.d/default.conf 中配置 error_page /50x.html; er ...

  8. Windows10设置系统参数

     屏幕分辨率设置 电源屏幕显示时间 投影可以进行手机投影到电脑进行操作,远程桌面可以进行远程访问,如云服务器 设置桌面图标和背景 设置默认应用 安装软件,必备的几项软件 --其中个人认为(1)(2)是 ...

  9. opencv —— resize、pyrUp 和 pyrDown 图像金字塔(高斯金字塔、拉普拉斯金字塔)与尺寸缩放(向上采样、向下采样)

    我们经常会将某种尺寸的图像转化为其他尺寸的图像,如果需要放大或者缩小图像的尺寸,在 OpenCV 中可以使用如下两种方法: resize 函数,最直接的方法. pyrUp 和 pyrDown 函数,即 ...

  10. AGC018F - Two Trees

    题意 有两棵节点数均为 n 的有根树,你需要构造一个序列 \(X_1,X_2,...,X_n\).使得对于每一棵树的每一个节点, 若令它所有的后代(包括它本身)为 \(a_1,a_2,...,a_k\ ...