1008. Elevator (20)
来源:互联网 发布:外贸邦海关数据有用吗 编辑:程序博客网 时间:2024/06/05 04:06
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 1Sample Output:
41计算楼层差,判断上楼还是下楼,计算总和
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<stack>#include<algorithm>#include<cmath>using namespace std;int main(){int k;cin>>k;int sum=5*k;int now=0;for(int i=0;i<k;i++){int num;cin>>num;if(num>now){sum+=(num-now)*6;now=num;}else{sum+=(now-num)*4;now=num;} } 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)
- shell中的通配符
- hiho一下 第158周 非法二进制数
- 完美三角形
- Cocoapods updating local specs repositories
- 通讯录(使用数据库)
- 1008. Elevator (20)
- 发个声
- tensorflow中softmax_cross_entropy_with_logits函数的实现
- (转载)阿里面试回来,想和Java程序员谈一谈
- Android单点触摸与多点触摸
- swift 利用Opration和OprationQueue来下载网络图片
- 1009. Product of Polynomials (25)
- bzoj1895: Pku3580 supermemo
- git的基本使用