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 ...
随机推荐
- 使用appium模拟用户发送短信
一段简单粗糙的代码.主要是实现的功能是模拟用户发送短信的功能. python版本3.5.2 appium版本1.4.16.1 from appium import webdriver desired_ ...
- [实战经验]Macbook pro 苹果系统换window系统
1. Macbook的window软件驱动备份 通过Boot Camp助手进行window支持苹果驱动下载 2. 拆机把SSD固态硬盘放在主盘位置,把苹果的机械盘放在光驱位置 ...
- unknown software exception
打开cmd 输入下面代码,回车,等跑完即解决for %1 in (%windir%\system32\*.dll) do regsvr32.exe /s %1
- Mysql-5.7.10启动失败 。
Mysql-5.7.10在免安装后启动服务失败. 查看日志得到如下: 2016-02-19T03:41:05.557095Z 0 [Warning] TIMESTAMP with implicit D ...
- 【MySQL】InnoDB引擎ibdata文件损坏/删除后使用frm和ibd文件恢复数据
参考:http://my.oschina.net/sansom/blog/179116 参考:http://www.jb51.net/article/43282.htm 注意!此方法只适用于innod ...
- form提交时,传递额外的参数
在进行表单提交时,会遇到在提交前增加额外参数的情况,对此有如下几种解决方法: 1. 在表单里使用hidden的input,将参数放到里面. 缺点:在form表单里会增加一些input节点,感觉不爽. ...
- leetcode 38
38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows:1, 11, ...
- Oracle小数点格式化
1. select to_char(123456789.12345,'fm999999990.99') from dual; 如果fm后位数不足则会显示 ## select to_char(12345 ...
- 添加favicon.ico网站文件
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" me ...
- centos6.5下yum安装lnmp(适合刚入职的新手的方法)
新入职的员工,开始的时候都是让配环境,本地写代码用的wamp,在lnmp或lamp测试,除非有些土豪公司 用的是(果机). 另外安装时,把整个流程在脑子里先过一篇(记不全也没关系,一回生二回熟),重在 ...