# Halo

A magic place for coding

0%

## 钥匙盒问题

### 问题描述

有一个学校的老师共用N个教室，按照规定，所有的钥匙都必须放在公共钥匙盒里，老师不能带钥匙回家。每次老师上课前，都从公共钥匙盒里找到自己上课的教室的钥匙去开门，上完课后，再将钥匙放回到钥匙盒中。
钥匙盒一共有N个挂钩，从左到右排成一排，用来挂N个教室的钥匙。一串钥匙没有固定的悬挂位置，但钥匙上有标识，所以老师们不会弄混钥匙。
每次取钥匙的时候，老师们都会找到自己所需要的钥匙将其取走，而不会移动其他钥匙。每次还钥匙的时候，还钥匙的老师会找到最左边的空的挂钩，将钥匙挂在这个挂钩上。如果有多位老师还钥匙，则他们按钥匙编号从小到大的顺序还。如果同一时刻既有老师还钥匙又有老师取钥匙，则老师们会先将钥匙全还回去再取出。
今天开始的时候钥匙是按编号从小到大的顺序放在钥匙盒里的。有K位老师要上课，给出每位老师所需要的钥匙、开始上课的时间和上课的时长，假设下课时间就是还钥匙时间，请问最终钥匙盒里面钥匙的顺序是怎样的？

## 最小差值问题

### 问题描述

给定n个数，请找出其中相差（差的绝对值）最小的两个数，输出它们的差值的绝对值。

输入第一行包含一个整数n

## Introduction

A graph G consists of a set V, whose members are called the vertices of G, together with a set E of pairs of distinct vertices from V. These paris are called the edges of G. If e = (v, w) is an edge with vertices v and w, then v and w are said to lie on e, and e is said to be incident with v and w.

## Introduction

The idea of a HashTable is to allow many of the different possible keys that might occur to be mapped to the same location in an array under the action of the index function. Then there will be a possibility that two records will want to be in the same place, but if the number of records that actually occur is small relative to the size of the array, then this possibility will cause little loss of time. Even when most entries in the array are occupied, hash methods can be an effective means of information retrieval.

## Introduction

As you know, sequential can keep the keys in order, searching becomes much faster if we use a contiguous list and binary search. Binary trees provide an excellent solution to this problem. By making the entries of an ordered list into the nodes of a binary tree, we shall find that we can search for a target key in O(log n) steps, just as with binary search, and we shall obtain algorithms for inserting and deleting entries also in time O(log n).

## Introduction

In some old computer languages, pointers or other facilities for dynamic storage allocation are not provided. Lists are often implemented by using an array-based storage. This way to store data sometimes better than the dynamic one. This post will show how to implement linked lists using only integer variables and arrays.

## Introduction

Linked Lists have great advantages of flexibility over the contiguous representation of data structure, but they have one weakness: They are sequential lists; that is, they are arranged so that it is necessary to move through them only one position at a time. In this post, we can overcome this problem by using trees as data structure, with methods of pointers.