PTA (Advanced Level) 1008 Elevator
Elevator
The highest building in our city has only one elevator. A request list is made up with Npositive 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 Npositive 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
题目解析
本题首先给出一个整数n代表电梯会停留的层数,之后给出n个数,代表电梯具体停留的楼层,电梯初始在0层,每向上一层会消耗6秒,每向下一层会消耗4秒,在需停留层会停留5秒,电梯最后不需要返回0层。
模拟一下电梯的运行过程即可。
#include <bits/stdc++.h>
using namespace std;
int n, t = , nowf = ; //n为电梯需停留层数, t为已经消耗的时间, nowf是电梯当前所在的楼层
int main()
{
scanf("%d", &n); //输入电梯需停留层数
while(n--){
int floors;
scanf("%d", &floors); //输入下一个要停留的楼层
while(nowf < floors){ //向上运行
nowf++;
t += ;
}
while(nowf > floors){ //向下运行
nowf--;
t += ;
}
t += ; //停留
}
printf("%d\n", t);
return ;
}
PTA (Advanced Level) 1008 Elevator的更多相关文章
- PAT (Advanced Level) 1008. Elevator (20)
简单模拟. 注意a[i]==a[i-1]的情况. #include<iostream> #include<cstring> #include<cmath> #inc ...
- PTA(Advanced Level)1036.Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PTA (Advanced Level) 1007 Maximum Subsequence Sum
Maximum Subsequence Sum Given a sequence of K integers { N1, N2, ..., NK }. A continuous su ...
- PTA (Advanced Level) 1006 Sign In and Sign Out
Sign In and Sign Out At the beginning of every day, the first person who signs in the computer room ...
- PTA (Advanced Level) 1005 Spell It Right
Spell It Right Given a non-negative integer N, your task is to compute the sum of all the digits of ...
随机推荐
- html5之range
第一次以这种方式做笔记,希望可以加强自己对新知识的理解,更希望能得到更多朋友的指正. 言归正传: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 ...
- java基础-day28
第05天 MySQL 今日内容介绍 u 数据库的概述 u MySQL和SQLyog的安装和使用 u SQL语句 第1章 数据库的概述 1.1 数据库的概述 1.1.1 概述 l 什么是数据库 ...
- hdu 5056 所有字母数都<=k的子串数目
<a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=5056" style="font ...
- 走上模拟道路 HDU4891
http://vjudge.net/contest/view.action?cid=51327#problem/D Description Yoda: May the Force be with yo ...
- 4.css基础
1 Css概念 CSS 指层叠样式表 (Cascading Style Sheets)(级联样式表) Css是用来美化html标签的,相当于页面化妆. ◆样式表书写位置 2选择器 2.1 写法 选择器 ...
- Linux 下建立 SSH 隧道做 Socket 代理
背景 需要解决本地访问内部集群中各台机器上的内部web服务,但是内部集群不能直接访问,只能通过edge node节点跳转. 前提:edge node可以通过ssh方式访问,在edge node上可以访 ...
- collaborative filtering协同过滤
每次我想看电影的时候,都会去问我的朋友,小健.一般他推荐的电影,我都比较喜欢.显然不是所有人都有小健这样的能力.因为我碰巧和小健有类似的品味. 这个生活中的经验,实际上有着广泛的用途. 当系统需要为某 ...
- VS的一些实用快捷键及小技巧(不断更新)
在未选中文本的情况下: ctrl+x 剪贴并删除当前的行,可以用于快速删除整行代码 ctrl+c 复制当前行的代码 ctrl+l 删除当前行 组合键,需要按两次: ctrl+k,ctrl+c 注释当前 ...
- CentOS 7修改yum源为阿里源
1.备份本地源 1 # mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak 2.获取阿里yum源配置 ...
- PHP 中 var_export、print_r、var_dump 调试中的区别
1.output basic type 代码 $n = "test"; var_export($n); print_r($n); var_dump($n); echo '----- ...