1008. Elevator (20)
2015-12-06 09:59
591 查看
时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe 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来源: <http://www.patest.cn/contests/pat-a-practise/1008>
#pragma warning(disable:4996)
#include <stdio.h>
using namespace std;
int main(void){
int a = 0;
while (scanf("%d", &a)!=EOF){
int time = 0;
int b[100] = { 0 };
for (int i = 1; i <= a; i++)
{
scanf("%d", &b[i]);
}
for (int j = 1; j <= a; j++){
if (b[j]>b[j - 1])
time += (5 + 6 * (b[j] - b[j - 1]));
else
time += (5 + 4 * (b[j - 1] - b[j]));
}
printf("%d",time);
}
return 0;
}[/code]来自为知笔记(Wiz)
相关文章推荐
- Unity3D与MySQL
- Java中的三目运算符 详解
- Visual Studio 2013不能单步调试、不能断点调试的解决方法之一
- 集合的异或运算(对称差)
- 1007. Maximum Subsequence Sum (25)
- 设计模式之装饰者模式(二)---java中的装饰者I/O结构
- linux常用命令解解释
- 【Leetcode】Merge Sorted Array
- Chrome下JQuery的mouseup事件丢失
- Swift在实际项目中的应用
- Android之判断当前网络状态
- 1006. Sign In and Sign Out (25)
- 1005. Spell It Right (20)
- Ajax 调用方式
- JDeveloper Memory And Performance
- LNMP搭建Discuz
- Fedora 23(Server Edition)中构建Mail Server(Postfix+Dovecot)
- 62,OC多文件开发
- win7下安装配置node.js+express开发环境
- LNMP环境搭建