pat 1008 Elevator(20 分)
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 <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define wzf ((1 + sqrt(5.0)) / 2.0)
#define INF 0x3f3f3f3f
#define LL long long
using namespace std; const int MAXN = 1e6 + ; LL A[MAXN] = {}, n, ans = ; int main()
{
scanf("%lld", &n);
for (LL i = ; i <= n; ++ i)
scanf("%lld", &A[i]);
ans += n * ;
for (LL i = ; i <= n; ++ i)
if (A[i - ] <= A[i])
ans += (A[i] - A[i - ]) * ;
else
ans += (A[i - ] - A[i]) * ;
printf("%lld\n", ans);
return ;
}
pat 1008 Elevator(20 分)的更多相关文章
- 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 ...
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- 【PAT甲级】1008 Elevator (20分)
1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...
- 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 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甲级】1008 Elevator (20 分)
题意: 电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层).电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒. AAAA ...
- 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)(代码)
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 ...
随机推荐
- 图论-最小生成树<Kruskal>
昨天: 图论-最小生成树<Dijkstra,Floyd> 以上是昨天的Blog,有需要者请先阅读完以上再阅读今天的Blog. 可能今天的有点乱,好好理理,认真看完相信你会懂得 然而,文中提 ...
- 爬虫链接mongodb 以及多线程多进程的操作
一.连接mongodb 1. 设置数据库 client=pymongo.MongoClient(‘localhost’) 2. db=client[‘lag ...
- char 、signed char、unsigned char
看如下代码: char c = -1; signed char sc = -1; unsigned char uc = -1; printf("c=%d, sc=%d, uc=%d, cx= ...
- 设计模式C++描述----17.备忘录(Memento)模式
一. 备忘录模式 定义:在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. 结构图: 使用范围: Memento 模式比较适用于功能 ...
- R.Swift优雅加载资源文件
在新的项目中,接触到了一个很不错的框架R.swift,可以帮助更方便安全的使用资源文件,相信已经使用过的或者还没有接触过的,一旦使用过了解过它,会爱上这个框架工具! 一.R.swift特点 当项目bu ...
- spring cloud 调用接口间歇性返回http 500 - Internal Server Error的错误
查找了各种资料都没找到解决办法,token失效,网络问题,接口服务问题,基础服务问题,都考虑过,但是没能解决,偶尔发现服务器网络配置中存在一个virbr0虚拟网卡,问了下了网管,删除这个对服务并没有影 ...
- mybatis代理机制讲解
问题描述 在使用Mybatis开发中,或者和Spring整合中,在Dao层中的Mapper接口与xml中的sql对应着,在service中直接调用Dao中的方法就可以直接访问sql.如下所示: /** ...
- 配置Spring Boot 跨域后PUT,DELETE方法出现403Forbidden
配置类 @Configuration public class CorsConfiguration { @Bean public WebMvcConfigurer corsConfigurer() { ...
- Pytorch数据集读入——Dataset类,实现数据集打乱Shuffle
在进行相关平台的练习过程中,由于要自己导入数据集,而导入方法在市面上五花八门,各种库都可以应用,在这个过程中我准备尝试torchvision的库dataset torchvision.datasets ...
- 泛微ecology OA系统某接口存在数据库配置信息泄露漏洞
2漏洞详情 攻击者可通过该漏洞页面直接获取到数据库配置信息,攻击者可通过访问存在漏洞的页面并解密从而获取数据库配置信息,如攻击者可直接访问数据库,则可直接获取用户数据,由于泛微e-cology默认数据 ...