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<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int n,a[110],i,j,sum=0,t;
scanf("%d",&n);
a[0]=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>a[i-1])
{
t=a[i]-a[i-1];
sum+=6*t;
}
else
{
t=a[i-1]-a[i];
sum+=4*t;
}
sum+=5;
}
printf("%d\n",sum);
return 0;
}
1008. Elevator (20)的更多相关文章
- PAT 1008. Elevator (20)
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- 1008 Elevator (20分)
1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is ma ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- 【PAT甲级】1008 Elevator (20分)
1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...
- 1008 Elevator (20)(20 point(s))
problem The highest building in our city has only one elevator. A request list is made up with N pos ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- PAT Advanced 1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
随机推荐
- js对象1--杂志
1.对象数组 var arr = [ ] //直接量创建 var arr = array() //通过函数创建 2. 变量与对象 var a = 12; //变量,不属于谁(默认 ...
- Appium移动自动化测试(四)--先跑起来再说(第一个测试用例-手机YY)
说明 本文将详细说明如何使用Appnium完成:打开手机YY欢迎页面->按住屏幕向左滑动4次->按下"立即体验"按钮->按下"直播"按钮,的整 ...
- Photoshop Cs5 64位系统破解版下载(内含破解方法)
Photoshop Cs5 64位系统是电影.视频和多媒体领域的专业人士, 使用 3D 和动画的图形和 Web 设计人员, 以及工程和科学领域的专业人士的理想选择,下面提供Photoshop Cs5 ...
- SDUT 3340 数据结构实验之二叉树一:树的同构
数据结构实验之二叉树一:树的同构 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 给定两棵树 ...
- 学习练习 java面向对象存取款查询余额
package com.hanqi; public class Account { String ZhangHao; double CunKuanYuE; Account(String ZhangHa ...
- 华为OJ平台——尼科彻斯定理
题目描述: 验证尼科彻斯定理,即:任何一个整数m的立方都可以写成m个连续奇数之和. 例如: 1^3=1 2^3=3+5 3^3=7+9+11 4^3=13+15+17+19 输入 输入一个int整数 ...
- ios项目记录
1,如何隐藏状态栏 在基类中重载UIViewController.h中的这个方法 - (BOOL)prefersStatusBarHidden { // iOS7后,[[UIApplication s ...
- C和C++混合编译
关于extern_C 通常,在C语言的头文件中经常可以看到类似下面这种形式的代码: #ifdef __cplusplus extern "C" { #endif /**** som ...
- Excel 代码
package com.chinabase.common.util; import java.io.FileInputStream; import java.io.FileOutputStream; ...
- hdu2085
#include <stdio.h> int main(){ __int64 h[],l[]; int i,j; int n; ){ h[]=; l[]=; ;i<=n;++i){ ...