📄 unit2.~pas
字号:
////////////////////////////////////////////////////////////////////////////////
//题目:假设有一种细胞,从出生后第三秒起每秒(发育成熟了)都产生了一个新细胞,//
//后代细胞长到第三秒后也一样,每秒又分裂了一只细胞,假设所有细胞的寿命固定为 //
//10秒,且第9,10秒属于老年期细胞不再分裂,问从第1个细胞出生后的第N秒,总共存 //
//在多少个细胞?
//解题思路:先建立一个数组 //
//作者:王仁銮 //
//日期:2004-03-21 //
//QQ:13633497 Email:wrl_001@tom.com //
////////////////////////////////////////////////////////////////////////////////
unit Unit2;
interface
function GetCellNum(Num: word): LongWord;
implementation
function GetCellNum(Num: word): LongWord;
var //注释中假象细胞一秒为一岁
i:word;
j:byte;
TempNum:word;
Cell:array[0..9] of word;
begin
if Num<3 then
begin
Result:=1;
Exit;
end; //若执行下面的语句则初始化数据:一岁的细胞为零,两岁的细胞为一个
Cell[0]:=0;
Cell[1]:=1;
for j:=2 to 9 do
Cell[j]:=0;
for i:=3 to Num do
begin
TempNum:=0;
Cell[9]:=Cell[8];//原本10岁的细胞死去,8,9岁的细胞长为9,10岁且不再生子细胞
Cell[8]:=Cell[7];
for j:=7 downto 2 do
begin
Cell[j]:=Cell[j-1];//原本2至7岁的细胞长一岁且生了一个子细胞
TempNum:=TempNum+Cell[j];//本轮中生出的子细胞总数TempNum;
end;
Cell[1]:=Cell[0];//一岁的子细胞长为两岁
Cell[0]:=TempNum;//新生的子细胞
end;
Result:=0;
for j:=0 to 9 do
Result:=Result+Cell[j];//
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -