PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分)
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
PS:起初还想复杂了,看错以为当电梯不用的时候需要回到1层, 英语差没办法...
#include<iostream>
using namespace std;
int main() {
int n, now = 0, next, time = 0;
cin >> n;
for (int i = 0; i < n ; i++) {
cin >> next;
if (next - now > 0)
time += (next - now) * 6+5;
else
time += (now - next) * 4+5;
now = next;
}
cout << time;
return 0;
}
PAT 甲级 1008 Elevator (20)(代码)的更多相关文章
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- 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 甲级 1008 Elevator
https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 The highest building i ...
- 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 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 Elevator
PATA1008 Elevator The highest building in our city has only one elevator. A request list is made up ...
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- 1008 Elevator (20分)
1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...
随机推荐
- Swift字符串常用方法
1.0 比较两个字符串是否相等 判断字符串相等的方法是: ==. var str1 = "Hello world" var str2 = "Hello world&quo ...
- Oracle 导入大量数据
环境是这样的: 需要导入大量数据到Oracle,目前Oracle已建立索引和触发器了,导入的数据是树型结构,需要关联. 采用的方法是: 删除以前数据库的索引和触发器,用OracleBulkCopy批量 ...
- Qt的action控件中采用默认绑定,没有connect显示绑定!!!
使用qt创建界面时,可以选用代码设计也可以选用qt design来设计.最近看我同事的代码,以前写action都是使用connect链接槽函数的, 网上大多数人都是这样,然后我就纳闷,怎么没有conn ...
- maven(二)基于intellij idea搭建ssm的maven项目结构
项目配置文件整合步骤 1.这里使用maven来引入项目所需要的jar包,所以也就不需要手动来管理jar包了. pom.xml 配置模板如下: <project xmlns="http: ...
- aspectj ----- 简介
一.为什么写这个系列的博客 Aspectj一个易用的.功能强大的aop编程语言.其官网地址是:http://www.eclipse.org/aspectj/,目前最新版本为:1.7.0 RC1.但 ...
- html中表单的应用
2.表单 ***** 表单作用: 用于显示.收集信息,并将信息提交到服务器 表单两大部分: 1.实现数据交互的可见界面元素,即表单控件 2.提交表单后的处理操作 1.如何实现表单 语法:<for ...
- asp.net 修改AD账号信息
public void ADInfoEdit(ADUser adu) { try { DirectoryEntry dADM; DirectoryEntry objectuser = null; dA ...
- OWAPSP_ZAP使用
启动OWAPSP_ZAP后 netstat -pantu | grep 8080
- Android的框架功能说明
OkHttp网络框架 Picasso图片缓存框架 ORMLite数据库框架 GreenDao数据库框架
- ubuntu 印象笔记
1. 印象笔记剪裁,直接浏览器上百度搜索,下载浏览器插件,登陆即可.(不过,我遇到个问题,浏览器登陆的服务器貌似是国际版的,与pc上的服务器不同,也没有成功转换过来.两账户相互独立.) 2. 印象笔记 ...