算法求解(数学建模的问题)
刚看到有兄弟提问,没想出下文就结贴了,现重新开一贴征求算法:
原题:
有一条长阶梯,若每步跨2阶,则最最后剩一阶,若每步跨3 阶,则最后剩2阶,若每步跨5阶,则最后剩4阶,若每步跨6阶则最后剩5阶。只有每次跨7阶,最后才正好一阶不剩。请问这条阶梯共有多少阶?
C语言,使用如下程序:
输出为119。
那么,119是不是唯一的答案?不是,将程序更改为如下:
输出为:
the anwser is: 119
the anwser is: 329
the anwser is: 539
the anwser is: 749
the anwser is: 959
the anwser is: 1169
the anwser is: 1379
the anwser is: 1589
从这些输出可以观察到,从119开始,每个符合条件的答案之间相差210。
但为什么会相差210?第一个数为119,可不可以推算出来,而不用遍历?
如果用函数f(x)表示,则此函数有f(x+T)=f(x),周期T为210,这个函数如何建模?
原题:
有一条长阶梯,若每步跨2阶,则最最后剩一阶,若每步跨3 阶,则最后剩2阶,若每步跨5阶,则最后剩4阶,若每步跨6阶则最后剩5阶。只有每次跨7阶,最后才正好一阶不剩。请问这条阶梯共有多少阶?
C语言,使用如下程序:
#include <stdio.h>
int
main()
{
int i=0;
while (i+=7)
{
if ( (i-2)%3!=0 ) continue;
if ( (i-4)%5!=0 ) continue;
if ( (i-5)%6!=0 ) continue;
printf("the anwser is: %d\n", i);
break;
}
return 0;
}
输出为119。
那么,119是不是唯一的答案?不是,将程序更改为如下:
#include <stdio.h>
int
main()
{
int i=0;
while (i+=7)
{
if (i>10000)
{
break;
}
if ( (i-2)%3!=0 ) continue;
if ( (i-4)%5!=0 ) continue;
if ( (i-5)%6!=0 ) continue;
printf("the anwser is: %d\n", i);
}
return 0;
}
输出为:
the anwser is: 119
the anwser is: 329
the anwser is: 539
the anwser is: 749
the anwser is: 959
the anwser is: 1169
the anwser is: 1379
the anwser is: 1589
从这些输出可以观察到,从119开始,每个符合条件的答案之间相差210。
但为什么会相差210?第一个数为119,可不可以推算出来,而不用遍历?
如果用函数f(x)表示,则此函数有f(x+T)=f(x),周期T为210,这个函数如何建模?
...全文
相关推荐
粒子群算法在求解数学建模最优化问题中的应用
粒子群算法在求解数学建模最优化问题中的应用,希望能帮到参加建模的同志
粒子群算法在求解数学建模最优化问题中的应用.pdf
粒子群算法在求解数学建模最优化问题中的应用.pdf
MATLAB数学建模算法 图论算法 图论中几个典型问题的求解 共161页.pptx
MATLAB数学建模算法 图论算法 图论中几个典型问题的求解 共161页.pptx
基于网络流算法求解2023MathorCup数学建模比赛C题整数优化问题的创新研究_数学建模竞赛论文网络流算法应用整数优化问题求解Python编程实现Word文档撰写建模.zip
基于网络流算法求解2023MathorCup数学建模比赛C题整数优化问题的创新研究_数学建模竞赛论文网络流算法应用整数优化问题求解Python编程实现Word文档撰写建模.zip
数学建模-遗传算法求解TSP问题的MATLAB实现.zip
数学建模-遗传算法求解TSP问题的MATLAB实现.zip


