注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[hdu]1008 Elevator  

2012-08-03 14:07:36|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
水题=。 =。不多说了。

Elevator

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


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

Sample Output
17 41
 

Author
ZHENG, Jianqiang
 

Source
 

Recommend
JGShining



#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
int N,n[101];
while(cin>>N,N != 0)
{
n[0] = 0;
int time = 0;
for(int i = 1;i <= N;i++)
{
scanf("%d",&n[i]);
if(n[i] - n[i - 1] > 0) time += (n[i] - n[i - 1]) * 6 + 5;
else time += (n[i - 1] - n[i]) * 4 + 5;
}
cout<<time<<endl;
}
}


/*
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.
Sample Input
1 2
3 2 3 1
0


Sample Output
17
41
*/



  评论这张
 
阅读(186)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018