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 ...
随机推荐
- python常用算法题
一: #计算平均数,中位数和众数 #coding:utf-8 #计算平均数,中位数和众数 import random lst = [random.randint(0,10) for i in rang ...
- POJ2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 19024 Accepted: 7431 Descrip ...
- spring处理线程并发
http://www.open-open.com/bbs/view/1320130410702
- jQuery 与 或 的坑
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>< ...
- bootstrap增删改查
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- 使用PerfView监测.NET程序性能(四):折叠,过滤和时间范围选择
在上一篇文章中,我们使用了Perfview的分组功能.分组功能旨在对某些函数按照某个格式进行分组,以减少视图中的各种无关函数的数量.但仅有分组还不够,有时我们想将一些函数调用信息按某些条件过滤掉,例如 ...
- Python学习--和 Oracle 交互
python 连接oracle 数据库 1.安装 cx_oracle pip install cx_oracle 2.出现 cx_Oracle.DatabaseError: DPI-1047: 64- ...
- 背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom
[源码下载] 背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom 作者:webabcd 介绍 ...
- 【BZOJ3280】 小R的烦恼(费用流,建模)
有很浓厚的熟悉感?餐巾计划问题? 不就是多了几个医院,相当于快洗部和慢洗部开了分店. 考虑建图: 如果把每一天拆成两个点,一个表示需求,另一个表示拥有的话. 显然就是一个两边的图,考虑如果我现在有人, ...
- 【LA3485】 Bridge
前言 哈哈哈,垃圾微积分哈哈哈 前置知识:自适应Simpson法与微积分初步,学会编程 Solution 考虑一下我们有的是什么: 一段桥梁的横向距离,悬线的长度,以及高度. 我们发现如果我们重新设一 ...