1008. Elevator (20)
来源:互联网 发布:淘宝如何投诉卖家店铺 编辑:程序博客网 时间:2024/05/18 19:44
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
有一个问题是如果序列里有连续两个相同的数,那么应该停同一楼层两次,实际中应该是停留一次的时间,如果这样考虑的话不能AC,只能认为当两次楼层相同时停留10s。
#include <iostream>#include <vector>using namespace std;int main(){int n;cin>>n;vector<int> vec(n);for(int i=0;i<n;i++){cin>>vec[i];}int total=0,last_floor=0;for(int i=0;i<n;i++){if(vec[i] >= last_floor){total+=(vec[i]-last_floor)*6+5;last_floor=vec[i];}if(vec[i] < last_floor){total+=(last_floor-vec[i])*4+5;last_floor=vec[i];}}cout<<total<<endl;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)
- NLP系列(5)_从朴素贝叶斯到N-gram语言模型
- 思维导图之《机器视觉知识体系》
- hdoj 2035人见人爱A^B
- 用两个队列实现一个栈
- EJB(Enterprise Java Bean)概述
- 1008. Elevator (20)
- AVD之PANIC: Could not open ***
- 数据结构-链表
- 智慧北京开发第三天(中)
- cocos2d-x与安卓混编实现“更换头像”
- Android 布局(fill_content、wrap_content、match_parent)
- cocos2d-x通过jni实现c++和java互调
- 方言APP应用方言说使用指南
- HDU 2044 一只小蜜蜂... (递推)