1008 Elevator (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
题解:看懂题意模拟过程即可,水题
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
long long int sum=0;
int n;
while(scanf("%d",&n)!=EOF) {
int a[10005]= {0};
sum=5*n;
scanf("%d",&a[0]);
sum+=6*a[0];
for(int t=1; t<n; t++) {
scanf("%d",&a[t]);
if(a[t]-a[t-1]>0) {
sum+=(a[t]-a[t-1])*6;
} else {
sum+=abs(a[t]-a[t-1])*4;
}
}
cout<<sum<<endl;
}
return 0;
}
1008 Elevator (20 分)(模拟)的更多相关文章
- 1008 Elevator (20分)
1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- 【PAT甲级】1008 Elevator (20分)
1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...
- PAT (Advanced Level) Practice 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 nu ...
- 1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- 【PAT甲级】1008 Elevator (20 分)
题意: 电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层).电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒. AAAA ...
- 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) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
随机推荐
- JAVA编程中你一定要掌握的“快捷键”
JAVA编程常用快捷键 相信很多编程小白刚开始的时候,看向大神的时候都是双膝跪地满眼泪水的膜拜之情~不因为别的,就是因为他们可以随随便便敲出很多行代码,而且他们没有动鼠标!这时候就有人问了:“怎么才能 ...
- CI4框架应用五 - 加载视图
这节我们来看一下CI4框架中视图的加载, CI4中提供了几种方式加载视图. 1. 利用CI4框架提供的全局函数view(‘模板名’),如果需要传参数可以在第二个参数传一个数组 我们先修改一下之前定义的 ...
- JVM与Java体系结构
参考笔记:https://blog.csdn.net/weixin_45759791/article/details/107322503 前言 作为Java工程师的你曾被伤害过吗?你是否也遇到过这些问 ...
- CSS 学习第二天
超链接的样式: 1.颜色变化:未访问时的样式a:link:鼠标点击后的样式a:visited;鼠标放上去的样式a:hover;鼠标点击时的样式a:active 2.鼠标变小手:cursor:point ...
- 2020-05-27:SpringCloud用了那些组件?分布式追踪链怎么做的?熔断器工作原理?
福哥答案2020-05-27: SpringCloud分布式开发五大组件详解服务发现——Netflix Eureka客服端负载均衡——Netflix Ribbon断路器——Netflix Hystri ...
- flask-sqlalchemy同字段多条件过滤
举例 from sqlalchemy import or_,and_# from operator import or_, and_ allapp = AppServer.query.filter(a ...
- menset与fill
menset函数一般只对int型数组进行0.-1的赋值.原因:menset对数组是按字节赋值,对每个字节的赋值是相同的,故int的4个字节全部被赋相同的值,而0正好二进制编码全为0,-1的二进制编码全 ...
- STL函数库的应用第二弹——快排sort函数与结构体关键字排序
时隔20多天,本蒟蒻终于记起了他的博客园密码!!! 废话不多说,今天主题:STL快排函数sort()与结构体关键字排序 Part 1:引入和导语 首先,我们需要知道,algorithm库里有一些奇怪的 ...
- 手牵手,使用uni-app从零开发一款视频小程序 (系列下 开发实战篇)
系列文章 手牵手,使用uni-app从零开发一款视频小程序 (系列上 准备工作篇) 手牵手,使用uni-app从零开发一款视频小程序 (系列下 开发实战篇) 扫码体验,先睹为快 可以扫描下微信小程序的 ...
- PC,移动端H5实现实现小球加入购物车效果
HTML部分: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" ...