码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1008

时间:2017-11-09 22:42:08      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:输出   tor   else   str   tput   while   limit   正整数   建筑   

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

问题描述
我们城市的最高建筑只有一部电梯。
请求列表是由N个正数组成的。
数字表示电梯在哪个楼层停止,按规定的顺序。
电梯上升一层需要6秒,而下一层则需要4秒。
电梯将在每一站停留5秒钟。

对于给定的请求列表,您需要计算用于满足列表上请求的总时间。
电梯开始时在第0层,当请求完成时,不需要返回到地面。
 

输入
有多个测试用例。
每个例子都包含一个正整数N,然后是N个正数。
输入的所有数字都小于100。
带有N = 0的测试用例表示输入结束。
这个测试用例不需要处理。
 

输出
在每个测试用例的单行上打印总时间。

Sample Input
1 2
3 2 3 1
0
 
Sample Output
17
41
 
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int main()
 4 {
 5     int i,n,*a,floor,time;
 6     scanf("%d",&n);
 7     while(n!=0)
 8     {
 9         floor=0;
10         time=0;
11         a=(int*)malloc(n*sizeof(int));
12         for(i=0;i<n;i++)
13             scanf("%d",&a[i]);
14         for(i=0;i<n;i++)
15         {
16             floor-=a[i];
17             if(floor<0)
18                 time+=(-floor)*6+5;
19             else if(floor>0)
20                 time+=floor*4+5;
21             else       //这里要注意题目中同楼层也要算5秒时间。坑!!
22                 time+=5;
23             floor=a[i];
24         }
25         printf("%d\n",time);
26         free(a);
27         scanf("%d",&n);
28     }
29     return 0;
30 }

 

HDU1008

标签:输出   tor   else   str   tput   while   limit   正整数   建筑   

原文地址:http://www.cnblogs.com/BOW1203/p/7811199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!