PAT甲级——A1008 Elevator
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
太简单了,竟然是按要求的顺序进行升降,一点都没有说进行时间优化?!
#include <iostream>
using namespace std; int main()
{
int N;
cin >> N;
int pre = , now,sum = * N;//上一次停留在哪?现在要去的楼层,时间初始为要在 每一层的总停留时间
for (int i = ; i < N; ++i)
{
cin >> now;
if ((now - pre) > )//上
sum += (now - pre) * ;
else if ((now - pre) < )//下
sum += (pre - now) * ;
pre = now;//更新楼层
}
cout << sum << endl;
return ;
}
PAT甲级——A1008 Elevator的更多相关文章
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT 甲级 1008 Elevator
https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 The highest building i ...
- PAT甲级——1008 Elevator
PATA1008 Elevator The highest building in our city has only one elevator. A request list is made up ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级代码仓库
大道至简,知易行难.希望能够坚持刷题. PAT甲级真题题库,附上我的代码. Label Title Score Code Level 1001 A+B Format 20 1001 * 1002 A+ ...
- PAT甲级1131. Subway Map
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...
- PAT甲级1127. ZigZagging on a Tree
PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...
- PAT甲级1123. Is It a Complete AVL Tree
PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...
随机推荐
- css之页面三列布局之左右上下高度固定,中间自适应
第一种,绝对定位 !DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <tit ...
- 【JZOJ6389】小w学图论
description 小w这学期选了门图论课,他在学习点着色的知识.他现在得到了一张无向图,并希望在这张图上使用最多n种颜色给每个节点染色,使得任意一条边关联的两个节点颜色不同. 小w获得一张n个节 ...
- create table常用命令
CREATE TABLE students( stuID INTEGER NOT NULL , stuname ) not null, sex int NOT NULL ); CREATE TABLE ...
- csps模拟86异或,取石子,优化题解
题面:https://www.cnblogs.com/Juve/articles/11736440.html 异或: 考试时只想出了暴力 我们可以对于二进制下每一位w,求出[l,r]中有几个数在这一位 ...
- 贪心数列构造——cf1157D
一开始将数列设置为0 1 2 3 4 5 6... 然后从左到右遍历,每位不够就增加即可 #include<bits/stdc++.h> using namespace std; #def ...
- 修改docker+jenkins挂载目录
1.停止docker [root@jenkins data]# systemctl stop docker 2.创建目录,拷贝数据 [root@jenkins data]# mkdir -p /new ...
- 用VC++MFC做文本编辑器(单文档模式)
用VC++MFC做文本编辑器(单文档模式) 原来做过一个用对话框实现的文本编辑器,其实用MFC模板里面的单文档模板也可以做,甚至更加方便,适合入门级的爱好者试试,现介绍方法如下: < xmlna ...
- BZOJ 1087(SCOI 2005) 互不侵犯
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5333 Solved: 3101 [Submit][ ...
- 实现客户端连接Mysql数据库服务器
以前学习mysql的时候,都是部署在本机,这样不存在客户端主机与服务器主机连接的问题,都是直接用localhost登录就行. 今天因项目需要,我们把mysql部署在服务器上,然后客户端装了client ...
- android GPS: code should explicitly check to see if permission is available
转载的,感谢作者,由于我找了很久才找到这个解决方法,因此我自己再转一遍 原文链接 https://blog.csdn.net/qinwendou/article/details/77849048 if ...