Elevator
2015-07-20 21:36
330 查看
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51973 Accepted Submission(s): 28695
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
Print the total time on a single line for each test case.
[align=left]Sample Input[/align]
1 2
3 2 3 1
0
[align=left]Sample Output[/align]
17
41/*注意每次循环在什么地方初始化*/#include<stdio.h>
int main()
{
int a,i=0,j,f;
while(scanf("%d",&a)!=EOF)
{
if(a==0) break;
f=i=0;
for(j=1;j<=a;j++)
{
int b;
scanf("%d",&b);
if(f<b)
i+=(b-f)*6+5;
if(f>b)
i+=(f-b)*4+5;
if(f==b)
i+=5;
f=b;
}
printf("%d\n",i);
}
return 0;
}
相关文章推荐
- vc的环境变量配置和缺少mspdb60.dll的解决方法
- RatingBar的自定义
- 关于一点HTML的东西
- C语言各种预编译宏总结
- 查看程序符号表的几个命令
- OpenWrt配置绿联的usb转Ethernet网口驱动
- 常用的不会忘记,不常用却容易忘记的(持续更新······)
- 感想
- Gym 100712L Alternating Strings II(单调队列)
- JAVA实现二分查找
- POJ 3258 River Hopscotch
- 4 和tqy4+. ---PHP的循环总结
- 数据仓库简介
- C#软件开发实例.个人定制自己的屏幕抓图工具(八)加入了截图功能键盘
- php5.6及以上版本利用curl文件上传
- Linux基础---鸟哥Linux总结
- HDUOJ1093
- 简单地画图程序
- python百度贴吧爬虫,以及爬虫简要入门
- C语言如何操作内存和对NULL的解释