PAT甲级——1008 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<cstdio>
int main()
{
int stay=0,t;
int N,i,total=0;
scanf("%d",&N);
for(i=0;i<N;++i)
{
scanf("%d",&t);
if(t==stay)
{
total+=5;
continue;
}
if(t>stay)
total+=(t-stay)*6+5;
else
total+=(stay-t)*4+5;
stay=t;
}
printf("%d",total);
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
https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 The highest building i ...
- 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 ...
随机推荐
- Java查漏补缺(3)(面向对象相关)
Java查漏补缺(3) 继承·抽象类·接口·静态·权限 相关 this与super关键字 this的作用: 调用成员变量(可以用来区分局部变量和成员变量) 调用本类其他成员方法 调用构造方法(需要在方 ...
- Codeforces 1291B - Array Sharpening
题目大意: 一个数列是尖锐的 当且仅当存在一个位置k使得 a[1]<a[2]<a[3]<...<a[k] 且 a[k]>a[k+1]>a[k+2]>...&g ...
- soupui--替换整个case的url
添加新的URL 随便进入一个case的[REST]step,添加新的url 更换URL 添加完之后双击想要更换url的case,在弹出的窗口中点击URL按钮 在弹出的set endpoint窗口中选择 ...
- C++实现顺序表的14种操作
C++顺序表的操作 2017-12-27 // 顺序表.cpp: 定义控制台应用程序的入口点. //Author:kgvito YinZongYao //Date: 2017.12.27 #inclu ...
- zabbix安装及配置
一.安装zabbix_server 二.安装zabbix_agent 三.zabbix配置详解
- 4. 现代 javascript class 专题 和 异步专题
class 专题 定义 class //es5 类的定义 属性定义在 function 上, 方法定义在原型链上 function foobar(){ this.foo_ = 'foo'; this ...
- POJ - 1061 扩展欧几里德算法+求最小正整数解
//#pragma comment(linker, "/STACK:1024000000,1024000000") //#pragma GCC optimize(2) #inclu ...
- 对象创建模式之模块模式(Module Pattern)
模块模式可以提供软件架构,为不断增长的代码提供组织形式.JavaScript没有提供package的语言表示,但我们可以通过模块模式来分解并组织代码块,这些黑盒的代码块内的功能可以根据不断变化的软件需 ...
- java依赖包问题排查
使用算法 breeze.optimize.LBFGSB,出现如下问题: 看到github上一个issue的解决方法是使用最新版本的 org.scalanlp:breeze_2.11:1.0-RC2, ...
- 静态页面缓存(thymeleaf模板writer)
//前端html <!DOCTYPE html><html lang="en"> <head> <meta charset="U ...