经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C 语言 » 查看文章
(杭电 1008 电梯问题)Elevator - cafu-chino
来源:cnblogs  作者:cafu-chino  时间:2018/12/3 21:21:51  对本文有异议

Elevator

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30095 Accepted Submission(s): 16272

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. 1 2
  2. 3 2 3 1
  3. 0

Sample Output

  1. 17
  2. 41

水题(话说有这么zz的电梯吗23333)

代码样例

  1. #include <stdio.h>
  2. int main() {
  3. int t;
  4. while (scanf("%d",&t) != EOF,t != 0) {
  5. int time=0,temp=0;
  6. for(int i=0; i < t; i++) {
  7. int n;
  8. scanf("%d",&n);
  9. if(temp < n) {
  10. time=time+(n-temp)*6;
  11. temp=n;
  12. }
  13. if(temp > n) {
  14. time=time+(temp-n)*4;
  15. temp=n;
  16. }
  17. if(temp == n)
  18. time=time+5;
  19. }
  20. printf("%d\n",time);
  21. }
  22. return 0;
  23. }

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号