分金块问题的解决思想和算法设计
摘要:在日常生活中,分金块问题是一个常见的问题,人们总是会面临怎样比较大小。才能利用一种最高效的算法选出其中最大和最小的金块。本文给出了较为常用的两种算法—蛮力法和分治法。
关键词:分金块问题;蛮力法(非递归);分治法;
Points gold bullion problem solving thought and algorithm design
Abstract:In daily life, points gold bullion is a common p roblem, people will always face how to compare size. Can use one of the mostEfficient algorithm choose the maximum and minimum of the gold. This paper gives a more commonly used two kinds of algorithm, brute force method and partition method.
Keywords:Points gold bullion problem; Brute force method(Non recursive); Partition method;
1引言
递归调用是一种特殊的嵌套调用,是某个函数调用自己,而不是另外一个函数。递归调用一种解决方案,一种是逻辑思想,将一个大工作分为逐渐减小的小工作,比如说一个和尚要搬50块石头,他想,只要先搬走49块,那剩下的一块就能搬完了,然后考虑那49块,只要先搬走48块,那剩下的一块就能搬完了……,递归是一种思想,只不过在程序中,就是依靠函数嵌套这个特性来实现了。
由于回溯法是对解空间的深度优先搜索,因此在一般情况下可用递归函数来实现回溯法
2问题概述
老板有n个金块,希望最优秀的雇员得到其中最重要的一块,最差的雇员得到其中最轻的一块。假设有一台比较重量的仪器,如何用最少的比较次数找出最重和最轻的金块?
理解金块问题:以9以内的实例理解问题。
金块示例
问题:1.最重的是那块?用max标记。