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 ...
随机推荐
- 用python实现购物车功能
"""功能要求:1.要求用户输入自己拥有的总资产,例如:20002.显示商品列表的序号,商品名称,商品价格,让用户根据序号选择商品,然后加入购物车 例如: 1 电脑 19 ...
- Python 爬虫 多进程清洗代理
利用多线程检测代理网站提供的免费代理是否可用 import requests from lxml import etree import time import multiprocessing def ...
- 20155323刘威良第一次实验 Java开发环境的熟悉(Linux + IDEA)
20155323刘威良第一次实验 Java开发环境的熟悉(Linux + IDEA) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序 ...
- CH03 课下作业
CH03 课下作业 缓冲区溢出漏洞实验 缓冲区溢出攻击:通过往程序的缓冲区写超出其长度的内容,造成缓冲区的溢出,从而破坏程序的堆栈,造成程序崩溃或使程序转而执行其它指令,以达到攻击的目的. 缓冲区溢出 ...
- banwagon vps装wordpress
http://www.banwagong.com/213.html http://www.banwagong.com/225.html http://www.banwagong.com/230.htm ...
- 【转载】D3DXVec3TransformNormal and D3DXVec3TransformCoord
原文:D3DXVec3TransformNormal and D3DXVec3TransformCoord D3DXVec3TransformCoord 对向量进行变换,没啥好说明的,默认向量为行向量 ...
- 4709: [Jsoi2011]柠檬
4709: [Jsoi2011]柠檬 https://www.lydsy.com/JudgeOnline/problem.php?id=4709 分析: 决策单调性+栈+二分. 首先挖掘性质:每个段选 ...
- Zabbix学习之路(十)之分布式监控zabbix_proxy及交换机监控
1.Zabbix分布式监控 zabbix proxy 可以代替 zabbix server 检索客户端的数据,然后把数据汇报给 zabbix server,并且在一定程度上分担了zabbix serv ...
- STM32的备份寄存器测试
1. 研究STM3的备份寄存器,注意,如果要测试这个例程的话,VBAT不能和VDD接一起,必须分开. 2. 理解,备份寄存器可以有VBAT独立供电,也就是外接电池,备份寄存器在VBAT供电情况下,如果 ...
- Unity3D使用NGUI实现简单背包功能
前话 在许多类型游戏中我们经常会使用到背包,利用背包来设置相应角色属性,多了背包也会让游戏增色拓展不少. 那在Unity3D游戏开发中该如何编写背包系统呢?因为有高人开发了NGUI插件,因此我们进行简 ...