1008. Elevator (20)
来源:互联网 发布:邮政网络银行 编辑:程序博客网 时间:2024/06/05 16:59
PAT
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
输入N,电梯经过N次升降,电梯以0层为基点,上升一层用时6s,下降一层用时4s,每层停5s,求最终用时
代码
#include<iostream>using namespace std;int main(){ int a[104]={0}; int n,sum=0; cin>>n; for(int i=1;i<=n;i++)///电梯以0层为基点 { cin>>a[i]; if(a[i]-a[i-1]>0)///上升 sum+=(a[i]-a[i-1])*6+5; else///下降 sum+=(a[i-1]-a[i])*4+5; } cout<<sum; return 0;}
- 1008. Elevator (20)
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 闲聊
- 两块磁盘一起读写的设置方法
- 操作系统Unix、Windows、Mac OS、Linux的故事
- 求极值--三分
- IDEA创建工程
- 1008. Elevator (20)
- 如何用dede做企业单页页面并且调用单页内容
- java跳出双重for循环,跳出双重for循环的内部循环并不执行外重循环内代码
- openstack 创建虚拟机的时候报错: Failed to allocate the network(s), not rescheduling.].
- 上机五
- SQL Server 2008 / 2008 R2 定期自动备份数据库
- 计算机网络结构
- 使用逻辑卷管理器管理灵活存储
- LeetCode之路:371. Sum of Two Integers