elevator
来源:互联网 发布:黑刀秋水淘宝网 编辑:程序博客网 时间:2024/06/05 06:18
题目描述:
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.
大致思路:
就是一个简单的模拟,坐电梯,每层停留和上升有一个时间,注意一点细节就可以了。
代码:
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.
大致思路:
就是一个简单的模拟,坐电梯,每层停留和上升有一个时间,注意一点细节就可以了。
代码:
#include<stdio.h>#include<string.h>int main() { int n,i,tmp,floor[2000]; long time; while (scanf("%d",&n)!=EOF) { memset(floor,0,sizeof(floor)); time=0; for (i=1;i<=n;i++) { scanf("%d",&floor[i]); tmp=floor[i]-floor[i-1]; if (tmp>0) time+=tmp*6+5; if (tmp<0) time+=-tmp*4+5; if (tmp==0) time+=5; } if (n!=0) printf("%ld\n",time); } }
0 0
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- 划分数
- 一句话摘录(软件工程)
- Subsequence
- a^b
- edge
- elevator
- HDU1098
- Fence Repair
- Expedition
- linux命令行参数处理
- YII CLinkPager分页
- Yii学习——-核心应用组件
- linuxcast学习笔记啊
- 数学很好学!