博客
关于我
PAT 1008. Elevator (20)
阅读量:427 次
发布时间:2019-03-06

本文共 1208 字,大约阅读时间需要 4 分钟。

1008. Elevator (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 
using namespace std;int main() { int n; int next,cnt=0; int time=0; scanf("%d",&n); while(n--) { scanf("%d",&next); if(next>cnt) time+=(next-cnt)*6; else time+=(cnt-next)*4; time+=5; cnt=next; }; printf("%d\n", time); return 0;}

转载地址:http://lijyz.baihongyu.com/

你可能感兴趣的文章
iOS UISlider的使用
查看>>
iOS Xcode 打包之后,不能输出日志
查看>>
UIPickerView的使用(二)
查看>>
iOS 多线程GCD简介
查看>>
不想eject,还咋修改create-react-app的配置?
查看>>
实现延迟消息队列
查看>>
写了一下 micropython 的文件系统单元测试
查看>>
说说字库和字模的故事,然后在 MaixPy 里实现打印中文字体(任意字体)吧!
查看>>
linux kernel version magic 不一致导致的模块 加载 (insmod) 不上
查看>>
线性代数应该这样学9:上三角矩阵、对角矩阵
查看>>
【科学计算】插值理论
查看>>
centos7一步一步搭建docker jenkins 及自定义访问路径重点讲解
查看>>
Java 读取Excel百分数保留原格式(即不转换为小数)的方法
查看>>
深度学习一:深度前馈网络和反向传播
查看>>
在wxPython使ListCtrl占据整个窗口
查看>>
微软面试题
查看>>
Google新玩法(转载)
查看>>
C#中Dispose和Close的区别!
查看>>
如何让服务在流量暴增的情况下保持稳定输出
查看>>
一个20年技术老兵的 2020 年度技术总结
查看>>