1008. Elevator (20)
来源:互联网 发布:c语言 逗号分隔符 编辑:程序博客网 时间:2024/06/06 20:06
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 1
Sample Output:
41
/** 思路: 分三种情况. > < ==*/#include<cstdio>using namespace std;const int UPTIME = 6;const int DOWNTIME = 4;const int STAYTIME = 5;int N;int main(void){ int last = 0; //last time floor int now; //now floor int ans = 0; scanf("%d", &N); for(int i = 0; i < N; ++i){ scanf("%d", &now); if(now > last){ ans += (now - last) * UPTIME; last = now; }else if(now < last){ ans += (last - now) * DOWNTIME; last = now; } ans += STAYTIME; } printf("%d", ans); return 0;}
- 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)
- 1008. Elevator (20)
- 1008. Elevator (20)
- 1008. Elevator (20)
- php 使用PDO,防止sql注入 简单说明
- java集合系列——Map之TreeMap介绍(九)
- 【前端】前端小知识点
- 近期关于eclipse和tomcat郁闷的事情
- Activity隐式调用学习记录,
- 1008. Elevator (20)
- Spring 框架的设计理念与设计模式分析
- 算法w2——Regular Expression Matching(leetcode 10)
- s5pv210开发板笔记
- 安卓自定义View
- LeetCode 315.Count of Smaller Numbers After Self
- Java设计模式-单类模式
- Spring MVC开发实现步骤
- HDU 6011 Lotus and Characters【思维】【pair】