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 ...
随机推荐
- 使用docker-compose运行微服务项目#eureka+config+auth+gateway+module
微服务架构中我们使用了必须的四个组件,eureka config gateway auth 其中config依赖eureka,auth依赖前两者,gateway又依赖auth 这样就确定了四个组件的启 ...
- docker使用(一)
docker相对于虚拟技术: 更高效的利用系统资源 更快的启动速度 一致的运行环境 持续交付和部署 更加轻松的迁移 更加轻松的维护和扩展 什么是docker镜像,容器: 可以说他就是一个模型,用面向对 ...
- Go黑帽子
使用go语言来实现python黑帽子和绝技的代码 1.unix密码破解器 package main import( "bufio" "flag" "i ...
- BrightScript 3D test - Roku (4)
My initial attempt to port over an old Actionscript program, here it goes in main.brs. Library " ...
- 20155231 cho2 课下作业
20155231 cho2 课下作业 2 调用附图代码,编写一个程序 "week0602学号.c",用show_int(), show_float()打印一下你的4位学号,参考教材 ...
- 实验一:实现求正整数1-N之间所有质数的功能,并进行测试。
实验一 Java开发环境的熟悉(Linux + Eclipse) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 命令行下的程序开 ...
- PostgreSQL参数学习:max_wal_senders
磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页[作者 高健@博客园 luckyjackgao@g ...
- 1116: [POI2008]CLO
1116: [POI2008]CLO https://lydsy.com/JudgeOnline/problem.php?id=1116 分析: 单独考虑每个联通块的情况. 设这个联通块里有n个点,那 ...
- dp合集 广场铺砖问题&&硬木地板
dp合集 广场铺砖问题&&硬木地板 很经典了吧... 前排:思想来自yali朱全民dalao的ppt百度文库免费下载 后排:STO朱全民OTZ 广场铺砖问题 有一个 W 行 H 列的广 ...
- 利用存储过程生成大量的数据(oracle,mysql)
在进行查询操作的性能测试时,往往需要测试大数据量模式下的查询功能的性能,这是就需要我们去创造一些测试数据来填充数据库,来模拟真是环境,造数据的方式有很多种,可以使用loadrunner,jmeter等 ...