PAT 甲级 1008 Elevator
https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016
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 <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int flo[111]; int cmp(int a, int b) {
if(b > a)
return 6 * (b - a);
else if(b < a)
return 4 * (a - b);
else return 0;
} int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &flo[i]); int time = 0, wait = 0;
wait = n * 5;
for(int i = 1; i < n; i ++) {
time += cmp(flo[i], flo[i + 1]);
}
time = time + wait + flo[1] * 6; printf("%d\n", time); return 0;
}
PAT 甲级 1008 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 (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- 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) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT Advanced 1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- PAT甲级——A1008 Elevator
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- PAT Advanced 1008 Elevator (20) [数学问题-简单数学]
题目 The highest building in our city has only one elevator. A request list is made up with N positive ...
- PAT甲级1008水题飘过
题目分析:上去下来到达的时间和数量 #include<iostream> using namespace std; ]; int main(){ int n; while(scanf(&q ...
- 【PAT甲级】1008 Elevator (20分)
1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...
随机推荐
- 使用aapt查看apk包名和启动的activity
执行命令: aapt dump badging F:\知乎.apk
- A.Activity planning
题目描述There is a collection of n activities E={1,2,..,n}, each of which requires the same resource, su ...
- FPGA时序逻辑中常见的几类延时与时间(五)
FPGA逻辑代码重要的是理解其中的时序逻辑,延时与各种时间的记忆也是一件头疼的事,这里把我最近看到的比较简单的几类总结起来,共同学习. 一.平均传输延时 平均传输延时 二.开启时间与关闭时间 开 ...
- Lingo安装
Lingo安装 Lingo简介 LINGO是Linear Interactive and General Optimizer的缩写,即"交互式的线性和通用优化求解器" ...
- 20+ Docs and Guides for Front-end Developers (No. 5)
It’s that time again to choose the tool or technology that we want to brush up on. If you feel like ...
- C语言复习20170716
C语言复习20170716 C数据类型 图片来自:C语言基本数据类型简介 C语言程序处理的数据有常量和变量两种形式. 常量是在程序中不能改变其值的量.例如:整型常量.实型常量.字符常量.字符串常量和枚 ...
- 【LG2183】[国家集训队]礼物
[LG2183][国家集训队]礼物 题面 洛谷 题解 插曲:不知道为什么,一看到这个题目,我就想到了这个人... 如果不是有\(exLucas\),这题就是\(sb\)题... 首先,若\(\sum_ ...
- 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 https://lydsy.com/JudgeOnline/problem.php?id=2288 分析: 贪心+堆+链表. 首先把序列变一下,把相 ...
- 你不需要jQuery You Don't Need jQuery
转载:https://github.com/oneuijs/You-Dont-Need-jQuery/blob/master/README.zh-CN.md You Don't Need jQuery ...
- pager-taglib分页注意事项
必须先导包,尤其是 jsp 这种工具类和标签库的