百钱百鸡,一百块钱买一百只鸡的递归算法 javascript实现
来源:互联网 发布:apache 域名泛解析 编辑:程序博客网 时间:2024/05/01 06:29
// 求百钱百鸡
function buy(ind, indexs, start) {
start++;
if (start > 2) {
return;
}
if (!indexs[start]) {
indexs[start] = 0;
}
for (indexs[start] = ind; indexs[start] <= 100; indexs[start]++) {
buy(0, indexs, start); // 递归调用
if (start == 2) {
if (5 * indexs[start - 2] + 3 * indexs[start - 1] + indexs[start] * 1 / 3 == 100
&&
indexs[start - 2] + indexs[start - 1] + indexs[start] == 100
) {
console.info("公鸡:" + indexs[start - 2] + "母鸡:" + indexs[start - 1] + "小鸡:" + indexs[start]);
break;
}
}
}
}
buy(0, {}, -1);
function buy(ind, indexs, start) {
start++;
if (start > 2) {
return;
}
if (!indexs[start]) {
indexs[start] = 0;
}
for (indexs[start] = ind; indexs[start] <= 100; indexs[start]++) {
buy(0, indexs, start); // 递归调用
if (start == 2) {
if (5 * indexs[start - 2] + 3 * indexs[start - 1] + indexs[start] * 1 / 3 == 100
&&
indexs[start - 2] + indexs[start - 1] + indexs[start] == 100
) {
console.info("公鸡:" + indexs[start - 2] + "母鸡:" + indexs[start - 1] + "小鸡:" + indexs[start]);
break;
}
}
}
}
buy(0, {}, -1);
0 0
- 百钱百鸡,一百块钱买一百只鸡的递归算法 javascript实现
- 昨天在china-pub买了一百块钱书
- 三十年里一百块钱的变化
- 枚举算法;100块钱买100只鸡;重点掌握枚举的优化与约束;
- 一百个铜钱买了一百只鸡,其中公鸡一只5钱、母鸡一只3钱,小鸡一钱3只,问一百只鸡中公鸡、母鸡、小鸡各多少。
- JavaScript中常用的一百零七条语句
- JavaScript中常用的一百零七条语句
- 80后用一百块钱搞定70后
- js一百零一夜之第三夜javascript 简单动画实现
- 一百以内的素数
- 一个人花8块钱买了只鸡,9块钱卖了,又10块钱买回来,11块钱又卖了,他赚了多少钱?
- 一个一百行内的现代的javascript路由
- 现在有100块钱,一只公鸡5块,一只母鸡3块,三个小鸡1块。现在让你用100块钱买到100只鸡(大小不限)运用循环,和if语句实现
- js一百零一夜之第七夜-javaScript this 的用法
- JAVA的 计机二级 那个网站有<南开一百题>买
- “三只猫,三分钟,捉三只老鼠,多少只猫,一百分钟,捉一百只老鼠”有感
- 上一百层的男人
- “我爱你”的一百种说法
- mysql 添加索引 mysql 如何创建索引
- 设有以下存储过程,阅读存储过程,根据存储过程写出使用代码,并在网页中显示结果??如何弄那?
- JavaCV配置
- wcf abc开发2
- android 滑动菜单SlidingMenu的实现
- 百钱百鸡,一百块钱买一百只鸡的递归算法 javascript实现
- eclipse打开报错
- 简单的自定义提示框(alert)
- Tsung参数说明
- VTK5.8.0自带例子运行错误修改
- matlab用于试验设计回归分析实验结果的例子
- Python文件目录判断和创建
- @Override 时出错误:
- dynamic_cast