HDU 1008 (Elevator)
来源:互联网 发布:手机视频点播软件 编辑:程序博客网 时间:2024/06/03 14:28
Elevator
Problem Description
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.
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
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 23 2 3 10
Sample Output
1741#include <stdio.h>int main(){int t;while(scanf("%d",&t)&&t){ int a[t],ans=t*5; //此题不用考虑连续相同楼层需要停的情况a[0]=0;for(int i=1;i<=t;i++ ){scanf("%d",&a[i]);if(a[i]>=a[i-1]){ans+=(a[i]-a[i-1])*6;}else{ans+=(a[i-1]-a[i])*4;}}printf("%d\n",ans);}}
阅读全文
0 0
- HDU 1008 Elevator
- hdu 1008Elevator
- HDU 1008 Elevator
- HDU 1008 Elevator
- hdu 1008 elevator 水
- HDU 1008 Elevator
- Hdu 1008 - Elevator
- HDU 1008 Elevator
- HDU--1008--Elevator
- hdu 1008 Elevator
- HDU-1008 Elevator
- HDU 1008 Elevator
- hdu 1008 Elevator
- Hdu--1008--Elevator
- hdu 1008 Elevator
- hdu 1008 Elevator
- hdu-1008-Elevator
- hdu 1008 Elevator
- 输入并逐行输出
- android相关错误
- 浏览器内核和性能优化总结
- spring和springmvc的区别
- 阻塞队列BlockingQueue
- HDU 1008 (Elevator)
- 哪个项目管理工具好用到哭?JIRA VS 华为软件开发云
- poj3176
- 第1章:阿里云机器学习实践之路 / 第3节:推荐系统--基于协同过滤的商品推荐
- C++ Builder中实现拖放功能
- ajax提交文件到服务器
- 私有继承与保护继承
- 使用一个for循环打印二维数组和三维数组
- 娜娜梦游仙境系列——吃不完的糖果(一维DP某个区间和最大