Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 49406    Accepted Submission(s):
27244

Problem Description
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
There are multiple test cases. Each case contains a
positive integer N, followed by N positive numbers. All the numbers in the input
are less than 100. A test case with N = 0 denotes the end of input. This test
case is not to be processed.
 
Output
Print the total time on a single line for each test
case.
 
Sample Input
1 2
3 2 3 1
0
 
Sample Output
17
41
 
#include<stdio.h>
int main()
{
int n,m,j,i,l,t,sum;
int a[110];
while(scanf("%d",&n)&&n!=0)
{
m=0;sum=0;
a[0]=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>m) //上楼的情况
{
sum+=(a[i]-a[i-1])*6+5;
m=a[i];
}
else if(a[i]<m) //下楼的情况
{
sum+=(m-a[i])*4+5;
m=a[i];
}
else if(a[i]==m) //在相同楼层的问题
{
sum+=5;
m=a[i];
}
}
printf("%d\n",sum);
}
return 0;
}

  

hdoj 1008 Elevator的更多相关文章

  1. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. Hdoj 1008.Elevator 题解

    Problem Description The highest building in our city has only one elevator. A request list is made u ...

  3. Problem : 1008 ( Elevator )

    好操蛋啊,电梯竟然能原地不动,你大爷的,这逻辑,太弱智了.... Problem : 1008 ( Elevator )     Judge Status : Accepted RunId : 103 ...

  4. PAT 1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  5. PAT 1008 Elevator

    1008 Elevator (20 分)   The highest building in our city has only one elevator. A request list is mad ...

  6. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  7. 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 ...

  8. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

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

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

随机推荐

  1. Qt:使用自定义的字体

    Qt:使用自定义的字体 1. 下载字体文件 2. 加载字体文件 3. 使用字体   QFontDatabase::addApplicationFont("XENOTRON.TTF" ...

  2. 214. Shortest Palindrome

    题目: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of ...

  3. 210. Course Schedule II

    题目: There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have ...

  4. 利用CCProxy管理小型企业的上网行为

    本实验以实例方式,从操作条件.背景.需求.以及具体要求的几个部分进行说明. 1. 操作条件: 装有Windows Server 2003系统,安装了代理服务程序的虚拟机一台 2. 背景: 为了提高员工 ...

  5. 在SQLite中使用索引优化查询速度

    在进行多个表联合查询的时候,使用索引可以显著的提高速度,刚才用SQLite做了一下测试. 建立三个表: create table t1 (id integer primary key,num inte ...

  6. poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)

    题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...

  7. poj 3009 Curling 2.0( dfs )

    题目:http://poj.org/problem?id=3009 参考博客:http://www.cnblogs.com/LK1994/ #include <iostream> #inc ...

  8. LinkedBlockingQueue

    LinkedBlockingQueue是一个基于已链接节点的.范围任意的blocking queue的实现.    此队列按 FIFO(先进先出)排序元素.队列的头部 是在队列中时间最长的元素.队列的 ...

  9. BZOJ2150: 部落战争

    题解: 把每个点拆成入点和出点,因为必须经过一次且只能经过一次.所以在两个点之间连一条上界=下界=1的边. 然后再s到每个入点连边,每个出点向t连边,点与点之间... 求最小流就可以过了... (感觉 ...

  10. 流行的MySql版本

    简介 MySQL是历史上最受欢迎的免费开源程序之一.它是成千上万个网站的数据库骨干,并且可以将它(和Linux)作为过去10年里Internet呈指数级增长的一个有力证明. 那么,如果MySQL真的这 ...