1008 Elevator
题意
给定电梯上行下行以及等待需要处理的时间,给定电梯所要执行的序列,计算处理完这个序列所要花费的时间
思路
简单
源码
line_number: true1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <iostream> #include <stdio.h> #include <map> #include <vector> #include <queue> #include <string> #include <cstring> using namespace std;
int main() { int iN; cin>> iN; int iFloor; int iLastFloor = 0; int iCost = 0; for(int i = 0; i < iN; i++) { cin >> iFloor; int iStep = iFloor - iLastFloor; if(iStep > 0) { iCost += iStep * 6; } else { iCost -= iStep * 4; } iLastFloor = iFloor;
iCost += 5; } cout<< iCost <<endl; return 0; }
|