1008. Elevator (20)[C语言]
来源:互联网 发布:淘宝客有要交钱的 编辑:程序博客网 时间:2024/06/05 12:49
1008. Elevator (20)
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 Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:3 2 3 1Sample Output:
41
#include <stdio.h>#include <stdlib.h>int main(){ int a[50000]; int n,i ; scanf("%d",&n); long sum = 0; for(i = 0 ; i < n ; i++){ scanf("%d",&a[i]); if(i==0){ sum =sum+ 6*a[0]+5; } else{ if(a[i] > a[i-1]){ sum =sum+ 6*(a[i]-a[i-1]) + 5; }else{ sum=sum+ (a[i-1]-a[i])*4 + 5; } } } printf("%ld",sum); return 0;}
- 1008. Elevator (20)[C语言]
- 【c++】PAT (Advanced Level)1008. Elevator (20)
- 【PAT甲级】【C++】1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)-PAT
- 【PAT】1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- PAT 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- POJ 1031 Fence 笔记
- Node.js建站之详解express与ejs(二)
- gdb+gdbserver调试ARM程序
- linux shell基础三之替换
- 近期总结+计划(5月份)
- 1008. Elevator (20)[C语言]
- [latex tikz]画曲线
- Collections.sort
- http://dl.hi-spider.com/pkg/free_unreg.pkg
- Python Notes (8)
- jQuery Ajax使用实例
- Android-消息机制(一):过程及源码分析
- 添加ArcGismap 内置图层属性模块
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误