PAT (Advanced Level) Practise:1008. Elevator
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 <stdio.h> int main(void)
{
int N;
int i, pre, cur;
int delta;
int time; pre = ;
time = ;
scanf("%d", &N);
for(i = ; i < N; i++)
{
scanf("%d", &cur);
if(cur - pre >= )
{
delta = cur - pre;
time += (delta * );
}
else
{
delta = pre - cur;
time += (delta * );
}
pre = cur;
}
printf("%d", time + N * ); return ;
}
运行结果:
PAT (Advanced Level) Practise:1008. Elevator的更多相关文章
- PAT (Advanced Level) Practise:1002. A+B for Polynomials
[题目链接] This time, you are supposed to find A+B where A and B are two polynomials. Input Each input f ...
- PAT (Advanced Level) Practise:1001. A+B Format
[题目链接] Calculate a + b and output the sum in standard format -- that is, the digits must be separate ...
- PAT (Advanced Level) Practise:1027. Colors in Mars
[题目链接] People in Mars represent the colors in their computers in a similar way as the Earth people. ...
- PAT (Basic Level) Practise:1008. 数组元素循环右移问题
[题目连接] 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… A ...
- PAT (Basic Level) Practise:1040. 有几个PAT
[题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Basic Level) Practise:1032. 挖掘机技术哪家强
[题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...
- PAT (Advanced Level) Practise 1004 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...
- PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)
http://www.patest.cn/contests/pat-a-practise/1099 A Binary Search Tree (BST) is recursively defined ...
随机推荐
- 从容而优雅(leisurely and elegant)
每时每刻, 我都变得更好了. ----- 法国心理学家 埃米尔 . 库埃 每时每刻, 我都变得更忙了. ----- 罗伯特 . 西奥迪尼 咬牙切齿的寒风, 昏暗的路灯, 默默的走过那一段从教室到寝 ...
- jquery总结05-常用事件03-键盘事件
键盘事件 .keydown() 键盘按下触发,返回的的是键盘按键代码 .keyup() 键盘松手触发,返回的是键盘按键代码 .keypress() 键盘按下触发,返回的是敲击的字符的ASCII码
- 32位和64位系统区别及int字节数
理论上来讲 我觉得数据类型的字节数应该是由CPU决定的,但是实际上主要由编译器决定(占多少位由编译器在编译期间说了算). 常用数据类型对应字节数 可用如sizeof(char),sizeof(ch ...
- transition&transform,CSS中过度和变形的设置
设置样式的过度效果transition-property: none/all; transition-duration:2s;运动时间,默认是0秒 transition-delay:0s; 延迟时间默 ...
- ASP.NET MVC Html.Partial/Html.RenderPartial/Html.Action/Html.RenderAction区别
1. @Html.Raw() 方法输出带有html标签的字符串: <div style="margin:10px 0px 0px;border:1px;border-color:red ...
- 查看本机的IP地址方法:
查看本机的IP地址方法:对于XP系统:方法一:如果右下角系统托盘区有本地连接的小电脑,双击小电脑→支持,就可以看到本机IP地址.无线连接也是一样.方法二:开始→运行cmd /k ipconfig,IP ...
- openssl evp 哈希算法(md5,sha1,sha256)
1. 简述 openssl提供了丰富密码学工具,一些常用的哈希算法 比如md5,sha 可以直接用提供的md5.h ,sha.h 接口使用: 为了方便开发者使用,openssl 又提供了一个EVP, ...
- spark standalone模式单节点启动多个executor
以前为了在一台机器上启动多个executor都是通过instance多个worker来实现的,因为standalone模式默认在一台worker上启动一个executor,造成了很大的不便利,并且会造 ...
- Unity ShaderLab学习总结
http://www.jianshu.com/p/7b9498e58659 Unity ShaderLab学习总结 Why Bothers? 为什么已经有ShaderForge这种可视化Shader编 ...
- 找做IT的男朋友会不会没有隐私
找做IT的男朋友会不会没有隐私你不觉得自己在网上不断的“秀”啊,“晒”啊的行为才是根本所在吗?你应该怕自己的这种行为才对吧-—————————————————————————————————————— ...