hdu-oj 1008 Elevator
来源:互联网 发布:sql美化工具 编辑:程序博客网 时间:2024/06/05 20:13
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 43137 Accepted Submission(s): 23681
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题目大意:输入N表示要上的楼层,从第一层起始。计算所需时间;解题思路:上一层花费6s停留5s,下楼4s。附代码:#include <stdio.h>#include <string.h>int main(){ int n,m,i,j; int a[110],sum; while(scanf("%d",&n)!=EOF&&n!=0) { memset(a,0,sizeof(a));sum=0; for(i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=1; for(i=0,j=i+1;i<n;j++,i++) { if(a[i]<a[j]) sum+=(a[j]-a[i])*6; else sum+=(a[i]-a[j])*4; } printf("%d\n",sum+(n+1)*5+1); } return 0;}
0 0
- hdu-oj 1008 Elevator
- Hdu oj 2553 Elevator(坑题)
- 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
- 新浪天气API返回数据对照表
- 设计模式--6大原则--开闭原则
- IOS写一个可以支持全屏的WebView
- Square Coins<母函数>
- Codeforces 455C —— Civilization(并查集,树上最长链)
- hdu-oj 1008 Elevator
- 单链表常见操作
- 栈
- 树-堆结构练习——合并果子之哈夫曼树
- LeetCode-Combinations
- lightoj 1022
- 继承ViewGroup重写onMeasure方法的详解
- Unity基础开发----用unity自带Animation组件制作动画
- C++11线程指南(5)--线程的移动语义实现