简单模拟。

注意a[i]==a[i-1]的情况。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std; const int maxn=+;
int n,a[maxn]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
a[]=;
int ans=;
for(int i=;i<=n;i++)
{
if(a[i]>a[i-]) ans=ans+(a[i]-a[i-])*,ans=ans+;
else if(a[i]<a[i-]) ans=ans+(a[i-]-a[i])*,ans=ans+;
else ans=ans+;
}
printf("%d\n",ans);
return ;
}

PAT (Advanced Level) 1008. Elevator (20)的更多相关文章

  1. 【PAT甲级】1008 Elevator (20分)

    1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up ...

  2. PTA (Advanced Level) 1008 Elevator

    Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...

  3. PAT (Advanced Level) 1077. Kuchiguse (20)

    最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...

  4. PAT (Advanced Level) 1061. Dating (20)

    简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...

  5. PAT (Advanced Level) 1035. Password (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  6. 【PAT甲级】1008 Elevator (20 分)

    题意: 电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层).电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒. AAAA ...

  7. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  8. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  9. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

随机推荐

  1. Mysql 锁机制

    innodb引擎提供了针对表级锁和行级锁 这个文章说的是行级锁 Lock有两种类型: 1,s-lock(共享锁),拥有该锁的transaction可以对row进行read操作 2,x-lock(排它锁 ...

  2. sqlserver低版本生成插入脚本

    --将表数据生成SQL脚本的存储过程 CREATE PROCEDURE dbo.UspOutputData @tablename sysname AS declare @column varchar( ...

  3. MySQL主从配置【转载】

    1.主从服务器分别作以下操作:  1.1.版本一致  1.2.初始化表,并在后台启动mysql  1.3.修改root的密码 2.修改主服务器master:   #vi /etc/my.cnf     ...

  4. 安装apache服务出错,无法启动此程序,因为计算机中丢失VCRUNTIME140.dll 尝试重新安装此程序以解决此问题

    错误信息:无法启动此程序,因为计算机中丢失VCRUNTIME140.dll 尝试重新安装此程序以解决此问题 错误场景:在使用["D:\Program Files\httpd-2.4.20-x ...

  5. 访问WEB-INF下的jsp/html

    基于Servlet的声明,WEB-INF不作为Web应用的公共文档树的一部分.因此,WEB-INF 目录下的资源不是为客户直接服务的.因此客户端不能直接访问WEB-INF下的文件,但是可以通过requ ...

  6. iOS开发 GET、POST请求方法:NSURLSession篇

    NSURLConnection,在iOS 9被宣布弃用,本文不使用NSURLConnection进行网络编程,有兴趣的童鞋可以参考: iOS开发 GET.POST请求方法(NSURLConnectio ...

  7. 【递归与分治】 poj 1017

    递归与分治经典例题    要点在于对3*3箱子的讨论 #include <iostream> #include <cstdio> using namespace std; in ...

  8. Android按钮单击事件的四种常用写法总结

    很多学习Android程序设计的人都会发现每个人对代码的写法都有不同的偏好,比较明显的就是对控件响应事件的写法的不同.因此本文就把这些写法总结一下,比较下各种写法的优劣,希望对大家灵活地选择编码方式可 ...

  9. Hibernate 系列教程5-双向多对一

    主要讲解inverse和cascade的用法 cascade定义的是关系两端对象到对象的级联关系: 而inverse定义的是关系和对象的级联关系(管理外键的值). inverse 属性默认是false ...

  10. LightOJ 1336 Sigma Function 算数基本定理

    题目大意:f(n)为n的因子和,给出 n 求 1~n 中f(n)为偶数的个数. 题目思路:算数基本定理: n=p1^e1*p2^e1 …… pn^en (p为素数): f(n)=(1+p1+p1^2+ ...