PAT甲级1008
来源:互联网 发布:mac电脑打不开照片权限 编辑:程序博客网 时间:2024/06/05 15:13
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<cstdio>#include<algorithm>#include<vector>#include<map>using namespace std;int main(){int N;scanf("%d", &N);int sum = 0;int floor;int oldfloor = 0;for (int i = 0; i < N; i++){scanf("%d", &floor);if (oldfloor < floor){while (oldfloor < floor){oldfloor++;sum += 6;}sum += 5;}else if (oldfloor > floor){while (oldfloor > floor){oldfloor--;sum += 4;}sum += 5;}else {sum += 5;}}printf("%d", sum);return 0;}
- PAT(甲级)1008
- PAT甲级1008
- PAT甲级1008
- PAT甲级1008
- PAT甲级 1008
- 浙大PAT甲级-1008
- PAT甲级1005-1008
- PAT 甲级 1008
- PAT甲级1008(Java)
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1009
- LeetCode278 find the first bad version
- c语言学生通讯系统
- 哈理工 hrbust 正确的日期格式
- OkHttp3 接口回调 UI线程
- 史上最全的maven pom.xml文件教程详解
- PAT甲级1008
- 设计模式 - 工厂方法
- Unity3D游戏开发入门学习笔记
- 算法提高 格式化数据输出
- 网上商城SSH一条线
- android 禁止viewpager预加载
- hrbust 哈理工 统计地雷数量
- Maven慕课网教程笔记
- 杭电ACM(1005)Number Sequence