HDU-1008-Elevator(Java版本+简单模拟+恶心水果)

Elevator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 50645    Accepted Submission(s): 27932

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

Source

ZJCPC2004

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1009 1021 1003 1108 1019

其实按道理来说,这题是简单的不能再简单的模拟电梯!可是我们大家一般的思路不是这样的,

我们会求出它上升最高的楼层,然后算出他上升用的时间,和下降用的时间,然后求出他停留

的时间.再相加!然后这题恶心之处体现了!

对于测试数据:

3  2  3  1

41

每层停一下,是指在 0->2->3->1在2,3,1层每层停一下,就是说!3->1这个地方的2层是不停,然

后注意连续输入相同楼层,照样得停,就是输入 2 1 1 答案是16秒而不是11秒.

并且电梯不会走最短路经的方法...它只会按照输入顺序,上升或者下降,简单模拟一下就可以ac!

还好以前在学校oj做过这题.......不然非得吐血!(学校oj中文题在下面!!)

import java.io.*;
import java.util.*;

public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		while(input.hasNext())
		{
			int n = input.nextInt();
			if(n==0)
				break;
			int begin=0,stop=0,sum=0;                //begin表示前面电梯所在的楼层,stop表示电梯要达到的楼层
			for(int i=0;i<n;i++)
			{
				stop = input.nextInt();
				if(stop>begin)
				{
					sum+=(stop-begin)*6+5;
				}
				else
				{
					sum+=(begin-stop)*4+5;
				}
				begin = stop;
			}
			System.out.println(sum);
		}
	}
}

1419: 电梯来了

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 176  Solved: 123

[Submit][Status][Web
Board
]

Description

某高层大厦仅有一座电梯。给定一个电梯要停留楼层的序列(N个非负整数),请你算出电梯完成这个停留序列共花费多少秒。设电梯每上一层楼需要6秒,每下一层需要4秒,每次在停留楼层需要等待5秒。请记住,电梯总是从第0层(地下室)开始运行,并且再也不需要返回地下室了。

Input

输入数据包含多组测试数据。每组数据为一行,包含一个非负自然数N,然后跟着N个非负整数(表示要停留的楼层序列),这些整数都小于100。若N为0,则输入结束,不需要进行处理。

Output

对于每组测试数据,输出完成该停留序列需要花费的总时间(秒数)。

Sample Input

1 23 2 3 15 1 5 4 3 10

Sample Output

174171

HINT

Source

[Submit][Status][Web
Board
]

时间: 2024-10-11 22:59:34

HDU-1008-Elevator(Java版本+简单模拟+恶心水果)的相关文章

模拟/hdu 1008 Elevator

题意 开始电梯在0层 给出n个指令,每个代表下一步停到哪层 每往上一层需要6秒,往下一层需要4秒,停止需要5秒 求总时间 分析 数据很小,模拟即可喵- Accepted Code 1 /* 2 PROBLEM:hdu1007 3 AUTHER:Nicole Lam 4 MEMO:模拟 5 */ 6 7 8 #include<cstdio> 9 using namespace std; 10 11 int main() 12 { 13 int n; 14 scanf("%d"

hdu 1200 To and Fro(简单模拟或DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1200 To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5129    Accepted Submission(s): 3550 Problem Description Mo and Larry have devised

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

HDU 5268 ZYB loves Score (简单模拟,水)

题意:计算Bestcoder四题的得分. 思路:直接模拟,4项分数直接计算后输出.注意不要低于百分之40的分. 1 //#include <bits/stdc++.h> 2 #include <iostream> 3 #include <cstdio> 4 #define LL long long 5 using namespace std; 6 const int N=10; 7 int a[N]; 8 int b[N]; 9 10 int cal() 11 { 12

HDU 5059 Help him(简单模拟题)

http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那就输出YES,其它的都是NO. 这个字符串是整数的条件: 1.如果它是正整数,它只包含前导不是0的数(这个数前面没有零). 2.如果它是负整数,只包含一个'-'符号,任然没有前导0. 3.除此之外都不是非法的 解题思路: http://bestcoder.hdu.edu.cn/ 这里有 要注意: 0

HDU ACM 1035 Robot Motion 简单模拟题

分析:一步步的走,走出矩阵则说明没有环,若走到已经走过的地方,说明有环,按格式输出结果,OK. #include<iostream> using namespace std; #define N 15 int dir[4][2]={-1,0,1,0,0,-1,0,1}; char map[N][N]; int vis[N][N]; char ch[]="NSWE"; int n,m; int id(char c) { int i; for(i=0;i<4;i++) i

Java简单模拟Android中Handler-Message机制

在Android中主线程与子线程的通信十分重要,Google工程师为我们提供了Handler-Message机制来解决他们之间的交互问题.今天,我们就来简单理解Handler-Message机制的原理,在Java中简单模拟该机制.代码示例Github地址HandlerDemo 首先,看一下简单流程图(不太专业) 由上图可知,流程中主要相关类有Handler.Message.MessageQueue.Looper:下面,我们就围绕它们来简单分析该流程图: 1.我们一般在主线程创建Handler,接

HDU 4891 简单模拟

The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035    Accepted Submission(s): 355 Problem Description As a programming contest addict, Waybl is always happy to take part in vario

HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1404    Accepted Submission(s): 926 Problem Description In the anc