`
endual
  • 浏览: 3545254 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

HDU ACM 1008

 
阅读更多

 

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int STOP = 5;
		int UP = 6;
		int DOWN = 4;
		Scanner cin = new Scanner(System.in);
		int n = 0;
		List list = new ArrayList();
		while ((n = cin.nextInt()) != 0) {
			int nowFloor = 0;
			int sum = 0;
			for (int j = 0; j < n; j++) {

				int nextFloor = cin.nextInt();

				if (nextFloor > nowFloor) { // 如果是大于当前层的

					int jian = nextFloor - nowFloor; // 相差几层
					sum = sum + STOP + UP * jian;
					nowFloor = nextFloor;
					continue;
				}
				if (nextFloor < nowFloor) { // 如果下一次是小于当前层了
					int jian = nowFloor - nextFloor;
					sum = sum + STOP + DOWN * jian;
					nowFloor = nextFloor;
					continue;
				}
				if (nextFloor == nowFloor) { // 如果是相同的

					sum = sum + STOP;
					continue;

				}
			}// end for
			list.add(sum);
		} // end while

		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	} // end main

} // end class

 

 

 

Elevator

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


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
 

Author
ZHENG, Jianqiang

 

分享到:
评论

相关推荐

    HDU_2010.rar_hdu 2010_hdu 20_hdu acm20

    【标题】"HDU_2010.rar"是一个压缩包文件,其中包含了与"HDU 2010"相关的资源,特别是针对"HDU ACM20"比赛的编程题目。"hdu 2010"和"hdu 20"可能是该比赛的不同简称或分类,而"hdu acm20"可能指的是该赛事的第20届...

    hdu acm 教案(7)

    HDU ACM教案是针对ACM/ICPC(国际大学生程序设计竞赛)的训练教程,旨在帮助参赛者提升算法和编程技能。"搜索入门"这部分内容是教程中的一个重要章节,主要介绍在解决算法问题时如何有效地运用搜索策略。在这个章节...

    hdu_ACM.rar_ACM_hdu_hdu acm_hdu_ACM_杭电ACM

    杭电hdu acm资料所用杭电的acm题

    (HDUACM201303版_07)背包专题

    杭电ACM课件2014版之 (HDUACM201303版_07)背包专题

    hdu acm 教案(3)

    HDU ACM教案是针对ACM/ICPC(国际大学生程序设计竞赛)的训练教程,旨在提升参赛者在算法和编程方面的能力。动态规划是计算机科学中一种强大的问题解决方法,尤其在处理最优化问题时非常有效。在这个教案中,我们将...

    (HDUACM2010版_13)二分匹配及其应用

    杭电ACM课件2014版之(HDUACM2010版_13)二分匹配及其应用

    (HDUACM2010版_08)母函数

    (HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数

    HDU_ACM培训课件(完整版)

    HDU_ACM培训课件是面向参与ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest,简称ICPC)的学员准备的一套完整的教程资源。这个压缩包包含了丰富的学习资料,旨在帮助参赛者提升编程技能...

    hdu acm 2010多校联合(10)1009

    【标题】"hdu acm 2010多校联合(10)1009" 是2010年ACM/ICPC(国际大学生程序设计竞赛)多校联合比赛的第十场比赛中的一道题目,编号为1009。这道题目涉及到算法竞赛中的常见问题解决策略,通常在这样的比赛中,...

    HDUACM2010版_14)Hash及应用

    HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用

    HDU acm-PPT课件

    【ACM入门与提高:HDU ACM竞赛课程详解】 ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest,简称ICPC或ACM/ICPC)是一项全球性的竞赛,旨在激发大学生对计算机科学的兴趣,提升他们的...

    杭电HDU ACM培训课件

    《杭电HDU ACM培训课件》是一份珍贵的学习资源,源自杭州电子科技大学的ACM竞赛培训课程。这些课件是官方论坛上分享的,旨在为那些积分不足无法获取资源或者对ACM编程竞赛感兴趣的初学者提供帮助。下面将详细阐述这...

    hdu acm2000至2099参考源码

    HDU ACM(ACM/ICPC国际大学生程序设计竞赛)是一个知名的编程竞赛平台,它提供了大量的算法题目供参赛者挑战。这些题目旨在提升参赛者的算法设计、编程和问题解决能力。"hdu acm2000至2099参考源码"是针对这个平台上...

    HDU ACM 部分简单题 JAVA

    【标题】"HDU ACM 部分简单题 JAVA" 涉及的是在编程竞赛领域,特别是ACM(国际大学生程序设计竞赛)中的题目解决,使用的编程语言是JAVA。HDU(杭州电子科技大学)是知名的在线编程竞赛平台,提供各种难度等级的编程...

    (HDUACM201403版_04)递推求解

    杭电ACM课件2014版之 (HDUACM201403版_04)递推求解

    hangdianACM.rar_hangdiana_hdu acm_www.hangdianacm_杭电

    这个压缩文件包含的是作者个人提交并解决的ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)题目,这些题目来源于HDU的在线编程平台。 【描述】"杭电的一些acm题目,都是我自己一个一...

    (HDUACM201303版_01)初识ACM 高清PPT

    杭电的ACM课件2014版之(HDUACM201303版_01)初识ACM

    (HDUACM2010版_06)并查集(最小生成树)

    (HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树

Global site tag (gtag.js) - Google Analytics