网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
Hanoi塔问题:要求将塔座A上的的所有n圆盘移到塔座B上,借助塔座C,并仍按同样顺序叠置。移动圆盘时遵守Hanoi塔问题的移动规则。由此设计出解Hanoi塔问题的递归算法正确的为:
A.void hanoi(int n, int A, int C, int B) { if (n > 0) { hanoi(n-1,A,C, B); move(n,a,b); hanoi(n-1, C, B, A); }
B.void hanoi(int n, int A, int B, int C) { if (n > 0) { hanoi(n-1, A, C, B); move(n,a,b); hanoi(n-1, C, B, A); }
C.void hanoi(int n, int C, int B, int A) { if (n > 0) { hanoi(n-1, A, C, B); move(n,a,b); hanoi(n-1, C, B, A); }
D.void hanoi(int n, int C, int A, int B) { if (n > 0) { hanoi(n-1, A, C, B);
参考答案和解析
void hanoi(int n, int A, int B, int C) { if (n > 0) { hanoi(n-1, A, C, B); move(n,a,b); hanoi(n-1, C, B, A); }
更多 “Hanoi塔问题:要求将塔座A上的的所有n圆盘移到塔座B上,借助塔座C,并仍按同样顺序叠置。移动圆盘时遵守Hanoi塔问题的移动规则。由此设计出解Hanoi塔问题的递归算法正确的为:A.void hanoi(int n, int A, int C, int B) { if (n > 0) { hanoi(n-1,A,C, B); move(n,a,b); hanoi(n-1, C, B, A); }B.void hanoi(int n, int A, int B, int C) { if (n > 0) { hanoi(n-1, A, C, B); move(n,a,b); hanoi(n-1, C, B, A); }C.void hanoi(int n, int C, int B, int A) { if (n > 0) { hanoi(n-1, A, C, B); move(n,a,b); hanoi(n-1, C, B, A); }D.void hanoi(int n, int C, int A, int B) { if (n > 0) { hanoi(n-1, A, C, B);” 相关考题
考题
Hanoi Tower 汉诺塔h(n)=2*h(n-1)+1h(1)=1初始所有铜片都在a柱上procedure hanoi(n,a,b,c:byte); {将第n块铜片从a柱通过b柱移到c柱上}
考题
阅读以下说明,回答问题1至问题3,将答案填入答题纸对应栏内。【说明】在某嵌入式处理器上,编写以下两段秸序(编译选项中,存储采用4字节对齐方式)。程序段1:struct studentl {char name [10] ;long sno;char sex;float score [4] ;*pl, al, bl;程序段2:union student2 {char name [10] ;long sno;char sex,float score [4] ;*p2, a2, b2;汉诺塔问题说明:有n个盘子在A处,盘子从小到大,最上面的盘予最小,程序要把这n个盘子从A处搬到C处,可以在E处暂存,但任何时候都不能出现大的盘子压在小的盘子上面的情况。下列是一段求解汉诺塔问题的C语言程序。include stdio . hvoid move (int n, char a, char c){static int Step=l;printf (Step %2d: Disk %d %c..-- %c\n, Step, n, a, c) ;Step++;}void Hanoi (int n, char a, char b, cnar c){if (nl){Hanoi (n-l, a, c, b) ;move (n, a. c) ;Hanoi (n-l, b, a, c) ;}else move (n,a,c);}void main(){Hanoi(3, ’A’, 、B’, 、C ’);}【问题1】(3分)C语言函数的一般格式为:函数类型 函数名 (参数列表){函数体;}简答下述问题,将答案填写在答题纸中对应栏目。(l)函数类型的含义是什么?(2)参数列表的含义是什么?(3)C语言函数之间的参数如何传递?【问题2] (6分)回答问题,将答案填写在答题纸中对应栏目。(1)sizeof(struct studentl)结果是多少(2) sizeof(union student2)结果是多少(3)变量a2在程序段2中定义,写出执亍以下语句后的输出结果。strcpy (a2. name,¨zhangwei¨);a2.sex=’f’;printf (%s¨, a2 .name);【问题3](6分)仔细阅读求解汉诺塔问题的C语言程序,完成其中(1)~(4)空白填空,将答案填入答题纸的对应栏内。运行结果为:Step1:Disk l A----CStep 2: (l)Step 3: Disk I C----BStep4: (2)Step 5: (3)Step 6: Disk 2 B----CStep 7: (4)
考题
According to the travel Web site, many travelers ______ staying at the Reliant Hotel in Hanoi.A. testify
B. conclude
C. recommend
D. disappoint
考题
东方明珠塔是亚洲第一、世界第三高塔,是我国建筑史上的一大奇迹。整座电视塔由塔座、3根直径为9米的擎天大柱、下球体、中球体和上球体组成。请问,旋转餐厅处于东方明珠塔的哪个位置()。A、塔座B、下球体C、中球体D、上球体
考题
单选题东方明珠塔是亚洲第一、世界第三高塔,是我国建筑史上的一大奇迹。整座电视塔由塔座、3根直径为9米的擎天大柱、下球体、中球体和上球体组成。请问,旋转餐厅处于东方明珠塔的哪个位置()。A
塔座B
下球体C
中球体D
上球体
考题
问答题位于青铜峡大坝陡峭山坡上的108塔共有多少行?多少个塔座?
热门标签
最新试卷