SDAU课程练习--problemG(1006)
题目描述
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
题目大意
简单的水题,电梯上升一层楼需要6s,下降需要4s,到达目的楼层后停留5s。给出目的楼层的列表。求需要的时间。
使用模拟法,模拟电梯的运行过程求得总时间。
AC代码
#include<iostream>#include<stdio.h>using namespace std;int main(){//freopen("date.in","r",stdin);//freopen("date.out","w",stdout);ios::sync_with_stdio(false);int N,m,sum,tem;while(cin>>N&&N!=0){sum=0;tem=0;for(int i=0;i<N;i++){cin>>m;if(m>tem)sum+=(6*(m-tem));else sum+=(4*(tem-m));tem=m;}cout<<sum+N*5<<endl;}}
SDAU课程练习--problemG(1006)的更多相关文章
- SDAU课程练习--problemQ(1016)
题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...
- SDAU课程练习--problemO(1014)
题目描述 Before bridges were common, ferries were used to transport cars across rivers. River ferries, u ...
- SDAU课程练习--problemB(1001)
题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...
- SDAU课程练习--problemA(1000)
题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...
- SDAU课程练习--problemC
题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...
- SDAU课程练习--problemE
problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...
- SpringMVC框架 课程笔记
SpringMVC框架 课程笔记 第0章 SpringMVC框架的核心内容 1.SpringMVC 概述 2.SpringMVC 的 HelloWorld 3.使用 @RequestMapping 映 ...
- MyBatis框架 课程笔记
MyBatis框架 课程笔记 第1章 MyBatis简介 1.1 MyBatis历史 1)MyBatis是Apache的一个开源项目iBatis, 2010年6月这个项目由Apache Softw ...
- .NET 提升教育 第一期:VIP 付费课程培训通知!
为响应 @当年在远方 同学的建议,在年前尝试进行一次付费的VIP培训. 培训的课件:点击下载培训周期:10个课程左右,每晚1个半小时培训价格:1000元/人.报名方式:有意向的请加QQ群:路过秋天.N ...
随机推荐
- leetcode441(巧妙利用取整和解方程)
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- JavaScript高级程序设计:第六章
第六章 面向对象的程序设计 一.理解对象 1.属性类型: ECMAScript中有两种属性:数据属性和访问器属性. (1)数据属性: 数据属性包含一个数据值的位置.在这个位置可以读取和写入值.数据属性 ...
- Git 操作标签的一些命令
如果标签打错了,也是可以删除: $ git tag -d v0.1Deleted tag 'v0.1' (was d96a49b) 如果要推送某个标签到远程,使用git push orign tagn ...
- bg-route
1.目录 homework add.html online.html offline.html res script action homework add.js 2.add.html<div ...
- 特殊字符 js处理
2.特殊字符传递过程中的处理 (1)js页面的处理 var url= "#@+&这些带有特殊字符"; url=encodeURI(encodeURI(url));//转码两 ...
- 编译安装SVN不结合apache
前言:独立SVN服务器不结合APACHE安装使用,连接独立SVN服务器也不是用HTTP协议.这是比较快捷的SVN服务器配置方法. 一.下载工具 1.subversion-1.6.17.tar.gz 2 ...
- js监听键盘方向键事件
<SCRIPT language=javascript> document.onkeydown = chang_page; function chang_page() { || ) loc ...
- cin详解(cin.get()、cin.getline()、cin.clear()、cin.sync())
在C中,输入输出用scanf和printf,在输入数据的同时还需说明数据的类型,如果输入数据较多,那就很麻烦,而C++中也有相似的东西cin和cout,它们来自C++的一个名叫" iostr ...
- 要想提高PHP的编程效率,你必须遵守的原则
用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中说 ...
- iOS开发工具——统计Crash的工具Crashlytics
简介 Crashlytic 成立于2011年,是专门为移动应用开者发提供的保存和分析应用崩溃信息的工具.Crashlytics的使用者包括:支付工具Paypal, 点评应用Yelp, 照片分享应用Pa ...