PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
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 1
Sample Output:
41
模拟水题
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std; int a[10004]; int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
a[0]=0;
int t=0;
for(int i=0;i<n;i++)
{
if(a[i+1]>a[i])
{
t+=(a[i+1]-a[i])*6;
}
else if(a[i+1]<a[i])
{
t+=(a[i]-a[i+1])*4;
}
}
t+=n*5;
printf("%d\n",t);
return 0;
}
最新文章
- [PHP源码阅读]count函数
- input 栏位光标末尾闪烁
- 使用nodejs+express+socketio+mysql搭建聊天室
- 数据结构和算法 &ndash; 12.高级查找算法(下)
- CF 600B Queries about less or equal elements --- 二分查找
- react webpack.config.js 入门学习
- Android布局_帧布局FrameLayout
- FDR
- JDBC中DAO事务函数模版
- Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
- ASP实现清除HTML标签,清除&;nbsp;空格等编码
- HTTP Content-type 对照表
- 王立平-NGUI
- Android的JunitTest
- 50个Java多线程面试题(上)
- 使用 LVS 实现负载均衡原理及安装配置详解
- Uva - 804 - Petri Net Simulation
- 11.4、Libgdx的音频之录制PCM音效
- 169. Majority Element求众数
- 奇偶个数-java