博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1008 Elevator
阅读量:4034 次
发布时间:2019-05-24

本文共 1430 字,大约阅读时间需要 4 分钟。

1、题目描述:

Elevator
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu

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

 

2、代码:

#include
int a[105];int main(){ int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; int sum=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { if(a[i]-a[i-1]>0) sum+=(a[i]-a[i-1])*6; else sum+=(a[i-1]-a[i])*4; } sum+=5*n; printf("%d\n",sum); } return 0;}

 

转载地址:http://phddi.baihongyu.com/

你可能感兴趣的文章
Selenium-Css Selector使用方法
查看>>
Linux常用统计命令之wc
查看>>
测试必会之 Linux 三剑客之 sed
查看>>
Socket请求XML客户端程序
查看>>
Java中数字转大写货币(支持到千亿)
查看>>
Java.nio
查看>>
函数模版类模版和偏特化泛化的总结
查看>>
VMware Workstation Pro虚拟机不可用解决方法
查看>>
最简单的使用redis自带程序实现c程序远程访问redis服务
查看>>
redis学习总结-- 内部数据 字符串 链表 字典 跳跃表
查看>>
iOS 对象序列化与反序列化
查看>>
iOS 序列化与反序列化(runtime) 01
查看>>
iOS AFN 3.0版本前后区别 01
查看>>
iOS ASI和AFN有什么区别
查看>>
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>
iOS app之间的跳转以及传参数
查看>>
iOS __block和__weak的区别
查看>>
Android(三)数据存储之XML解析技术
查看>>
Spring JTA应用之JOTM配置
查看>>