博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Elevator
阅读量:5306 次
发布时间:2019-06-14

本文共 1537 字,大约阅读时间需要 5 分钟。

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

题目意思:上楼每层需要6秒,下楼每层需要4秒,在到达的楼层还要停留5秒

1 #include
2 int main() 3 { 4 int n,i,count,f[100]; 5 while(scanf("%d",&n)!=EOF) 6 { 7 if(n==0) 8 break; 9 count=0;10 f[0]=0;11 for(i=1; i<=n; i++)12 {13 scanf("%d",&f[i]);14 if(f[i]>f[i-1])15 count=count+(f[i]-f[i-1])*6+5;16 else17 count=count+(f[i-1]-f[i])*4+5;18 }19 printf("%d\n",count);20 }21 return 0;22 }

明明是一道水题,可我还是看错意思了,以为在每一层都要停留,该死!

转载于:https://www.cnblogs.com/wkfvawl/p/8734449.html

你可能感兴趣的文章
23.C# 语言的改进
查看>>
任务12:Bind读取配置到C#实例
查看>>
数据库基础及T-SQL语句
查看>>
转载: kafka 配置文件详细说明
查看>>
正则入门分享
查看>>
2017-2018 20155309 南皓芯 信息安全基础设计第十周博客
查看>>
Linq聚合操作之Aggregate,Count,Sum,Distinct源码分析
查看>>
仿照 SQLHelper 写的 SQLiteHelper
查看>>
引用类型构造器
查看>>
Unity日记—对象缓存池
查看>>
安装gocode教程
查看>>
生成建表脚本(V3.0)
查看>>
Altium Designer中死铜的问题
查看>>
{转}每次从vss获取文件都是只读
查看>>
JS 去字符串空格 总结
查看>>
Win7和Ubuntu下mysql 安装配置
查看>>
HDOJ 3899 JLUCPC
查看>>
软件需求分析--结构化分析(SA)方法
查看>>
SpringBoot Aop打印参数
查看>>
react 事件绑定
查看>>