Halo

A magic place for coding

0%

游戏问题

问题描述

  有 n 个小朋友围成一圈玩游戏,小朋友从 1 至 n 编号,2 号小朋友坐在 1 号小朋友的顺时针方向,3 号小朋友坐在 2 号小朋友的顺时针方向,……,1 号小朋友坐在 n 号小朋友的顺时针方向。
  游戏开始,从 1 号小朋友开始顺时针报数,接下来每个小朋友的报数是上一个小朋友报的数加 1。若一个小朋友报的数为 k 的倍数或其末位数(即数的个位)为 k,则该小朋友被淘汰出局,不再参加以后的报数。当游戏中只剩下一个小朋友时,该小朋友获胜。
  例如,当 n=5, k=2 时:
 1 号小朋友报数 1;
 2 号小朋友报数 2 淘汰;
 3 号小朋友报数 3;
 4 号小朋友报数 4 淘汰;
 5 号小朋友报数 5;
 1 号小朋友报数 6 淘汰;
 3 号小朋友报数 7;
 5 号小朋友报数 8 淘汰;
 3 号小朋友获胜。

  给定 n 和 k,请问最后获胜的小朋友编号为多少?

Read more »

钥匙盒问题

问题描述

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

Read more »

最小差值问题

问题描述

  给定 * n * 个数,请找出其中相差(差的绝对值)最小的两个数,输出它们的差值的绝对值。

输入格式

  输入第一行包含一个整数 * n*。
第二行包含 * n * 个正整数,相邻整数之间使用一个空格分隔。

输出格式

输出一个整数,表示答案。

Read more »

Introdution

从这篇 post 开始,我将逐步介绍 java 的一些内容。我是利用了寒假的时间粗略地学习了 java 的一些知识,希望通过介绍自己的学习经历,能让大家对 java 有个大概的认识。今天,我们先来讲解一下如何在自己的 PC 上配置 java 的开发环境

Read more »

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.

Read more »

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.

Read more »

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).

Read more »

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.

Read more »