山东理工——1009

Elevator

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<iostream>
using namespace std;
int main(void)
{
	int n, i;
	int m,t,sum;
	while (cin >> n)
	{
		if (n == 0)
			break;
		cin >> m;
		t = m;
		sum = 6 * m;
		if (n == 1)
		{
			cout << 6 * m + 5 << endl;
			continue;
		}
		else
		{
			for (i = 1; i < n; i++)
			{
				cin >> m;
				if (m > t)
				{
					sum = sum + (m - t) * 6;
				}
				else if (m < t)
				{
					sum = sum + (t - m) * 4;
				}
				else;
				t = m;
			}
		}
		sum = sum + 5 * n;
		cout << sum << endl;
	}
	return 0;
}
### 山东理工大学数据结构链表教学资源 山东理工大学在数据结构的教学过程中,涉及到了多个与链表相关的实验和题目设计。通过分析已有的参考资料[^1][^3],可以发现该校注重实践操作能力的培养,尤其是在单链表的操作上。 #### 单链表的基础构建 根据引用中的描述,在《数据结构实验之链表一》中提到的任务是基于输入的一系列整数来创建并遍历一个单链表。这一部分的内容主要帮助学生理解如何动态分配内存以及掌握基本节点的连接方式。具体实现可以通过如下代码完成: ```c #include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node* next; } Node; Node* createList(int n) { Node *head = NULL, *tail = NULL; for (int i = 0; i < n; ++i) { int val; scanf("%d", &val); Node* newNode = (Node*)malloc(sizeof(Node)); newNode->data = val; newNode->next = NULL; if (!head) head = tail = newNode; else { tail->next = newNode; tail = newNode; } } return head; } void traverseAndPrint(Node* head){ while(head != NULL){ printf("%d ", head->data); head = head->next; } } ``` 此代码片段展示了如何读取一组整数值,并将其按顺序存入到新建立的单向链表之中。 #### 链表拆分的应用实例 进一步来看,《数据结构实验之链表五:单链表的拆分》则提出了更高层次的要求——即把原始列表分割成分别只含偶数项与奇数项的新列表。这种练习不仅加深了对于指针管理的理解,还锻炼了解决实际问题的能力。 以下是解决上述需求的一个可能方案: ```c // 定义函数用于分离链表... Node* splitEvenOddLists(Node* originalHead, Node** oddHeadRef){ // 实现逻辑省略... } ``` 以上方法未完全展示出来是因为它需要更详细的算法步骤说明才能完整呈现其功能。 #### 考试大纲提及内容 另外值得注意的是,在山东理工大学发布的2019年硕士研究生入学考试大纲里也提到了关于数据结构方面的考察要点[^2]。虽然具体的章节没有明确指出是否包含链表相关内容,但从以往经验推测,作为基础知识点之一,“线性表及其应用”必然会被覆盖其中。 ### 结论 综上所述,无论是本科阶段还是研究生层面的学习计划安排当中,都可以看到围绕着“链表”的一系列理论学习与动手实操相结合的设计思路贯穿始终。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值