c语言课程设计:选出一位幸运人士,一定要用递归算法!要源代码,流程图,和算法描述!
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/29 05:49:49
c语言课程设计:选出一位幸运人士,一定要用递归算法!要源代码,流程图,和算法描述!
一次大型派对的最后节目是选出一位幸运人士,该人将获得派对组织者准备的一个钻石戒指.而选择幸运人士的办法是让所有人员一字排列,然后从左至右点数,凡是奇数号的全部剔除.对于剩下的人员,又从左至右点数,逢奇数号就剔除.如此不断递归下去,直到只剩一人为止.此人即为幸运之人.请设计一个递归算法计算幸运之人所在的位置,并分析该算法的时间效率.
一次大型派对的最后节目是选出一位幸运人士,该人将获得派对组织者准备的一个钻石戒指.而选择幸运人士的办法是让所有人员一字排列,然后从左至右点数,凡是奇数号的全部剔除.对于剩下的人员,又从左至右点数,逢奇数号就剔除.如此不断递归下去,直到只剩一人为止.此人即为幸运之人.请设计一个递归算法计算幸运之人所在的位置,并分析该算法的时间效率.
这道题做ACM题目的时候做过,当时使用数组做的,最后因为效率太低通过不了.
G Josephus Problem
Time Limit:1000MS Memory Limit:65535K
题型: 编程题 语言: 无限制
描述
Josephus Problem is an ancient problem named for Flavius Josephus. There are people standing in a circle waiting to be executed. The counting out begins at the
first point in the circle and proceeds around the circle in a fixed direction. In each step, one person is skipped and the next person is executed. The elimination
proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom.
For example, if there are 10 people in the circle, the executed order is 2, 4, 6, 8, 10, 3, 7, 1, 9. So the 5th person survives.
Now we define a function J(n) to be the survivor’s number when there are n person in the circle, and J^2(n)=J(J(n)), for instance J^2(10)=J(J(10))=J(5)=3,
and J^3(n)=J(J(J(n))), and so on. Could you calculate J^m(n)?
输入格式
The input consists of a number of cases.
Each case contains integers n and m. 0
G Josephus Problem
Time Limit:1000MS Memory Limit:65535K
题型: 编程题 语言: 无限制
描述
Josephus Problem is an ancient problem named for Flavius Josephus. There are people standing in a circle waiting to be executed. The counting out begins at the
first point in the circle and proceeds around the circle in a fixed direction. In each step, one person is skipped and the next person is executed. The elimination
proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom.
For example, if there are 10 people in the circle, the executed order is 2, 4, 6, 8, 10, 3, 7, 1, 9. So the 5th person survives.
Now we define a function J(n) to be the survivor’s number when there are n person in the circle, and J^2(n)=J(J(n)), for instance J^2(10)=J(J(10))=J(5)=3,
and J^3(n)=J(J(J(n))), and so on. Could you calculate J^m(n)?
输入格式
The input consists of a number of cases.
Each case contains integers n and m. 0
任意选择一种排序算法,分别用流程图和PDL语言描述其详细过程
C语言用非递归算法求数列.
C语言背包问题递归算法
c语言算法流程图中的N和Y是什么意思
c语言 :用递归算法求整数m和n的最大公约数.为什么说有错误?
数据结构试验(用C语言)建立一棵二叉树,并用递归或者非递归的算法分别用先序.中序和后序遍历、谢谢
全排列、算法、C语言、递归、求帮忙
二叉树中序遍历非递归算法(c语言实现)
请问如何用C语言实现下面的迭代和递归的两种算法
分析下面问题,用自然语言和流程图描述算法.找出A、B、C三个变量中值最大的一个.
用递归算法描述Fibonacci数列的伪代码
[C语言]用递归算法编写一个程序求Fibonacci数列的第n项值