题目
Description
在城市的高层建筑物中,只有一部电梯,由N个正整数组成一个请求列表,列表中的数字表示电梯将在哪层停,电梯按列表顺序依次停靠。电梯每上行一层需要
花6秒时间,每下行一层需要花4秒时间,电梯每停一次需要用时5秒。
对于给定的请求列表,计算完成所有请求需要花费的时间,不考虑优先顺序,电梯从第0层开始,完成所有请求后又回到第0层。Input
包含多组数据,每组数据占一行,其中第一个正整数N表示请求列表中有N个数据,接下来是N个整数,如果N=0,则表示输入结束。
Output
对每组数据,输出所有请求的总时间。
Sample Input
1 2
3 2 3 1
0Sample Output
17
41
题解
直接模拟电梯的运行即可
代码
/* By:OhYee Github:OhYee HomePage:http://www.oyohyee.com Email:oyohyee@oyohyee.com Blog:http://www.cnblogs.com/ohyee/ かしこいかわいい? エリーチカ! 要写出来Хорошо的代码哦~ */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <vector> #include <list> #include <queue> #include <stack> #include <map> using namespace std; //DEBUG MODE #define debug 0 //循环 #define REP(n) for(int o=0;o<n;o++) bool Do() { int n; if(scanf("%d",&n),n == 0) return false; int floor = 0; int ans = 0; REP(n) { int temp; scanf("%d",&temp); if(temp < floor) { ans += 4 * (floor - temp); floor = temp; } if(temp > floor) { ans += 6 * (temp - floor); floor = temp; } } //ans += floor * 4; ans += n * 5; printf("%d\n",ans); return true; } int main() { while(Do()); return 0; }