杭电 1008 Elevator
来源:互联网 发布:爱普生l360清零软件 编辑:程序博客网 时间:2024/05/16 06:41
Elevator
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.
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 23 2 3 10
Sample Output
1741分析:提交了几次没过,问了问别人才知道输入0结束要有&&n
int main()
{
int n,a[100]={0},i;
while(cin>>n&&n)//输入0要结束,需用&&n来说明n非0!
{
int s=0,m=a[0];
for(i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]-m>0)
s+=(a[i]-m)*6;
else
s+=(m-a[i])*4;
m=a[i];
}
cout<<s+n*5<<endl;
}
return 0;
}
- 杭电1008 Elevator
- 杭电1008 Elevator
- 杭电1008 Elevator
- Elevator 杭电1008
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电 1008 Elevator
- 杭电 1008 Elevator
- 杭电1008-Elevator
- 杭电 1008 Elevator
- 杭电1008 Elevator
- 杭电ACM 1008Elevator
- 杭电ACM-1008 Elevator
- 杭电ACM-1008-Elevator
- 杭电acm 1008 Elevator
- 杭电 ACM 1008:Elevator
- 杭电ACM 1008Elevator
- 杭电 HDOJ 1008 Elevator
- ok6410 u-boot-2012.04.01移植七完善u-boot移植(u-boot移植结束)
- 第一次在csdn上
- Deep learning:十九(RBM简单理解)
- Surrounded Regions
- Java菜鸟学习之路之开篇——————准备工作!
- 杭电 1008 Elevator
- 小狐狸归来~~
- Markdown Cheatsheet
- GPS定位基本原理浅析
- 计算器,源代码
- LED子系统剖析
- c++中far,near区别
- NS2中基于AODV协议实现的请求洪泛攻击
- ubuntu 上安装 hadoop