HDOJ--1008
来源:互联网 发布:java定义一个银行账户 编辑:程序博客网 时间:2024/05/26 20:23
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57716 Accepted Submission(s): 31603
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
简单的数学题,读懂题意即可AC。
记得考虑特殊情况:如果电梯下次要去的楼层就是本层,该如何计时?
以下是我的AC代码:
#include<iostream>#include<cstdio>#define MAXN 10000using namespace std;int main(){ int n; while(scanf("%d",&n)==1 && n!=0) { int i,time=0; int a[MAXN]; a[0]=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { if(a[i]>a[i-1]) time+=(a[i]-a[i-1])*6+5; if(a[i]<=a[i-1]) time+=(a[i-1]-a[i])*4+5; } cout<<time<<endl; } return 0; }
0 0
- HDOJ 1008
- HDOJ 1008
- HDOJ--1008
- HDOJ 1008
- hdoj 1008
- hdu 1008 hdoj 1008
- HDOJ 1008: Elevator
- HDOJ--1008 Elevator
- HDOJ 1008 Elevator
- HDOJ-1008 Elevator
- HDOJ 1008 Elevator
- hdoj.1008 Elevator 20140728
- HDOJ 1008 Elevator
- hdoj 1008 难度*
- 【HDOJ】【1008】Elevator
- HDOJ 1008-Elevator【数学】
- HDOJ 1008 Elevator
- HDOJ 1008 Elevator
- Android之放大镜实现的两种方式
- Python中通过多个字符分割(split)字符串的方法
- 阿里云服务器搭建随笔(一)
- OpenGL ES 学习教程(八) 精密控制光照元素的 Material 材质系统
- Jenkins+maven+git 实现自动构建、权限管理、静态代码检测、远程部署、发送邮件功能
- HDOJ--1008
- PL/SQL 游标
- Bootstrap4
- 在Windows上安装PyCUDA和Theano
- 对com接口的访问
- Theano学习笔记:Theano的艰辛安装体验
- kettle xml 读取配置变量
- 使用GET实现一个简单的登入界面
- HTML5<input>