杭电1008(简单题)
来源:互联网 发布:线切割3b编程实例刀 编辑:程序博客网 时间:2024/06/05 21:16
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.
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 2
3 2 3 1
0
Sample Output
17
41
该题比较简单,看懂题意就行~注意,如果连续出现两个相同的楼层时,如:2 1 1,第二个1需要再停留5秒。
#include<stdio.h>int main(){ int N,i,cur_floor,dst_floor; int total_time; while(scanf("%d",&N)==1&&N>0) { total_time=0; cur_floor=0; for(i=1;i<=N;i++) { scanf("%d",&dst_floor); if(dst_floor>cur_floor) { total_time+=(dst_floor-cur_floor)*6+5; } else { total_time+=(cur_floor-dst_floor)*4+5; } cur_floor=dst_floor; } printf("%d\n",total_time); } return 0;}
- 杭电1008(简单题)
- 杭电1001(简单题)
- 杭电1004(简单题)
- 杭电 1008 Elevator(简单的数学问题)
- 杭电1013——Digital Roots(简单题)
- 杭电1019——最小公倍数(简单题)
- 杭电acm 折线分割平面(简单题)
- 杭电acm 1259ZJUTACM(简单题)
- 树状数组简单题----杭电1541
- 杭电 ACM 1035 简单模拟题
- 杭电--2069--Coin_Change(简单枚举题)
- 杭电1002(简单的大数)
- 杭电1003(简单dp)
- 杭电简单计算器
- 杭电1003(大数)简单的DP简单过
- 杭电1008题
- 杭电2151 简单DP
- 杭电2851 简单dp
- python
- Android自定义圆形头像
- Android Wear 交互表面设计及Android 双击事件监测实现
- 《第一行代码Android》学习日记6
- LeetCode---Unique Paths II
- 杭电1008(简单题)
- 排序算法Java描述:选择、冒泡、插入、希尔、归并、快速及三向切分快速排序
- 苹果发布iOS9.1 Beta 3:新增壁纸和表情
- c --副作用和顺序点
- 转自MIT牛人林达华的 “图˙谱˙马尔可夫过程˙聚类结构 ”————经典、透彻
- 事件驱动模型
- 极限优化:Haar特征的另一种快速计算方法-boxfilter
- 代码覆盖工具gcov/lcov的使用
- notepad++