HDOJ 1008
时间:2022-04-22
本文章向大家介绍HDOJ 1008,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25560 Accepted Submission(s): 13793
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
答案:
刚开始想的复杂了...本以为要用电梯算法.....没想到两个数减一下就成,想多了害人啊!
1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int n,i,m,last,now,sum;
6 while(cin>>n)
7 {
8 last=0;
9 sum=0;
10 if(n!=0)
11 {
12 for(i=0;i!=n;++i)
13 {
14 cin>>m;
15 now=m;
16 if(now<last)
17 {
18 sum+=(last - now)*4+5;
19 last=now;
20 }
21 else if(now == last)
22 {
23 sum+=5;
24 last=now;
25 }
26 else
27 {
28 sum+=(now-last)*6+5;
29 last=now;
30 }
31 }
32 cout<<sum<<endl;
33 }
34 else
35 break;
36 }
37 return 0;
38 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 独家 | 在Python编程面试前需要学会的10个算法(附代码)
- 为什么一个还没毕业的大学生能够把 IO 讲的这么好?
- 如何将单 master 升级为多 master 集群
- 为 Kubernetes 节点发布扩展资源
- Kubernetes 资源预留配置
- PHP一些常见的漏洞梳理
- File的基本操作
- 一文教你在Colab上使用TPU训练模型
- 如何在Docker容器中运行Docker [3种方法]
- [漏洞复现] 三.CVE-2020-0601微软证书漏洞及Windows验证机制欺骗复现
- PDF文件密码破解
- Ubuntu 制作离线源
- keycloak+istio实现基于jwt的服务认证授权
- dplyr 包arrange对数据排序
- ELK 日志报警插件 ElastAlert