想了一会了,在纸上画画写写,还是没搞出来,只能来这求助了.....
像大神求教求代码

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Cell
        {
            public static List<Cell> Cells = new List<Cell>();
            public int Life { get; set; }
            public Cell() { Life = 0; Cells.Add(this); }
            public void Deduce()
            {
                Life++;
                if (Life > 1 && Life < 5) Cells.Add(new Cell());
                if (Life == 5) Cells.Remove(this);
            }
        }    class Program
        {
            static void Main(string[] args)
            {
                Cell c = new Cell();
                for (int i = 1; i < 17; i++)
                    Cell.Cells.ToList().ForEach(x => x.Deduce());
                Console.WriteLine(Cell.Cells.Count);
            }
        }
    }71679
    Press any key to continue . . .
      

  2.   

    给你写个不带递归的吧using System;
    using System.Collections.Generic;
    using System.Linq;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var world = new List<Cell> { new Cell() };
                for (var i = 0; i < 17; i++)
                {
                    var copy = world.ToList();
                    copy.ForEach(c => c.Act(world));
                }
                Console.WriteLine("还有{0}个生物", world.Count);
                Console.ReadKey();
            }
        }    public class Cell
        {
            public int Age = 0;        public void Act(List<Cell> world)
            {
                if (Age < 3)
                    world.Add(new Cell());  //分裂出一个新细胞
                else if (Age >= 4)
                    world.Remove(this);     //从世界上消失
            }
        }
    }
      

  3.   

    嗯,“一天之后才能分裂”的话,那么要改一下using System;
    using System.Collections.Generic;
    using System.Linq;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var world = new List<Cell> { new Cell() };
                for (var i = 0; i < 17; i++)
                {
                    var copy = world.ToList();
                    copy.ForEach(c => c.Act(world));
                }
                Console.WriteLine("还有{0}个生物", world.Count);
                Console.ReadKey();
            }
        }    public class Cell
        {
            public int Age = 0;        public void Act(List<Cell> world)
            {
                if (Age > 0 && Age < 4)
                    world.Add(new Cell());  //分裂出一个新细胞
                else if (Age >= 5)
                    world.Remove(this);     //从世界上消失
            }
        }}真没想到,第17天过后,只剩下一个活的了。
      

  4.   

    晕死了!哈哈,上面全都少写了一句话
    using System;
    using System.Collections.Generic;
    using System.Linq;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var world = new List<Cell> { new Cell() };
                for (var i = 0; i < 17; i++)
                {
                    var copy = world.ToList();
                    copy.ForEach(c => c.Act(world));
                }
                Console.WriteLine("还有{0}个生物", world.Count);
                Console.ReadKey();
            }
        }    public class Cell
        {
            public int Age = 0;        public void Act(List<Cell> world)
            {
                if (Age > 0 && Age < 4)
                    world.Add(new Cell());  //分裂出一个新细胞
                else if (Age >= 5)
                    world.Remove(this);     //从世界上消失
                Age++;
            }
        }}
      

  5.   

    1t=1g独居
    2t=2g分身
    3t=4g1分身2分身+前天分身2
    4t=8g1分身2分身3分身4分身+前天分身4
    5t=(8-1)*2
    6t=(14-1)*2
    7t=(26-1)*2
    8t=50*2-2
    9t=98*2-2
    10t=(98*2-2)*2-2//194
    11t=((98*2-2)*2-2)*2-2//386
    12t=(((98*2-2)*2-2)*2-2)*2-2//770
    13t=1538
    14t=3074
    15t=6146
    16t=12290
    17t=24578
    这样逻辑分析和计算对?
      

  6.   

    1t=1g独居
    2t=2g分身
    3t=4g1分身2分身+前天分身2
    4t=8g1分身2分身3分身4分身+前天分身4
    5t=(8-1)*2(-原始1)
    6t=(14-1)*2(-第一次分身1)
    7t=(26-2)*2(-第二次2分身)
    8t=(50-4)*2(-第3次分身4)
    9t=(92-8-1)*2
    10t=(170-14-1)*2
    11t=(314-26-2)*2
    12t=(580-50-4)*2
    13t=(1068-92-8-1)*2
    14t=(1934-170-14-1)*2
    15t=(3498-314-26-2)*2
    16t=(6312-580-50-4)*2
    17t=(11372-1068-92-8-1)*2//20426
    发现上面分析错了,这次逻辑分析和计算对? 
      

  7.   


            public int Get(int day)
            {
                int count = 0;
                int n1 = 1, n2 = 0, n3 = 0, n4 = 0, n5 = 0;
                for (int i = 0; i < day; i++)
                {
                    int a = n1, b = n2, c = n3, d = n4, e = n5;
                    n5 = d;
                    n4 = c;
                    n3 = b;
                    n2 = a;
                    n1 = a + b + c;
                }
                count = n1 + n2 + n3 + n4 + n5;
                return count;
            }
      

  8.   

    1t=1原数(1)裂变数(0)老去数(-0)
    2t=2原数(1)裂变数(1)老去数(-0)
    3t=4原数(2)裂变数(2)老去数(-0)
    4t=8原数(4)裂变数(4)老去数(-0)
    5t=15原数(8)裂变数(8-1)老去数(-0)
    6t=28原数(15)裂变数(15-1)老去数(-1)
    7t=53原数(28)裂变数(28-2)老去数(-1)
    8t=100原数(53)裂变数(53-4)老去数(-2)
    9t=189原数(100)裂变数(100-(8-1))老去数(-4)
    10t=357原数(189)裂变数(189-(15-1))老去数(-(8-1))
    11t=674原数(357)裂变数(357-(28-2))老去数(-(15-1))
    12t=1273原数(674)裂变数(674-(53-4))老去数(-(28-2))
    13t=2404原数(1273)裂变数(1273-(100-(8-1)))老去数(-(53-4))
    14t=4540原数(2404)裂变数(2404-(189-(15-1)))老去数(-(100-(8-1)))
    15t=8574原数(4540)裂变数(4540-(357-(28-2)))老去数(-(189-(15-1)))
    16t=16192原数(8574)裂变数(8574-(674-(53-4)))老去数(-(357-(28-2)))
    17t=30579原数(16192)裂变数(16192-(1273-(100-(8-1))))老去数(-(674-(53-4)))
    推演出数字不知对否?
      

  9.   

    1t=1||||||a原数(1)+++++++++++++b裂变数(0)----------------------------------------------------------------------------------------------c老去数(0)
    2t=2||||||a原数(1)+++++++++++++b裂变数(1)----------------------------------------------------------------------------------------------c老去数(0)
    3t=4||||||a原数(2)+++++++++++++b裂变数(2)----------------------------------------------------------------------------------------------c老去数(0)
    4t=8||||||a原数(4)+++++++++++++b裂变数(4)----------------------------------------------------------------------------------------------c老去数(0)
    5t=15|||||a原数(8)+++++++++++++b裂变数(8-1=7)------------------------------------------------------------------------------------------c老去数(0)
    6t=27|||||a原数(15)++++++++++++b裂变数(15-1-1=13)--------------------------------------------------------------------------------------c老去数(1)
    7t=50|||||a原数(27)++++++++++++b裂变数(27-2-1=24)--------------------------------------------------------------------------------------c老去数(1)
    8t=92|||||a原数(50)++++++++++++b裂变数(50-4-2=44)--------------------------------------------------------------------------------------c老去数(2)
    9t=169||||a原数(92)++++++++++++b裂变数((92-(8-1=7)-4)=81)------------------------------------------------------------------------------c老去数(4)
    10t=311|||a原数(169)+++++++++++b裂变数((169-(15-1-1=13)-(8-1=7))=149)------------------------------------------------------------------c老去数(8-1=7)
    11t=572|||a原数(311)+++++++++++b裂变数((311-(27-2-1=24)-(15-1-1=13))=274)--------------------------------------------------------------c老去数(15-1-1=13)
    12t=1052||a原数(572)+++++++++++b裂变数((572-(50-4-2=44)-(27-2-1=24))=504)--------------------------------------------------------------c老去数(27-2-1=24)
    13t=1935||a原数(1052)++++++++++b裂变数((1052-((92-(8-1=7)-4)=81)-(50-4-2=44))=927)-----------------------------------------------------c老去数(50-4-2=44)
    14t=3559||a原数(1935)++++++++++b裂变数((1935-((169-(15-1-1=13)-(8-1=7))=149)-((92-(8-1=7)-4)=81))=1705)--------------------------------c老去数((92-(8-1=7)-4)=81)
    15t=6546||a原数(4540)++++++++++b裂变数((3559-((311-(27-2-1=24)-(15-1-1=13))=274)-((169-(15-1-1=13)-(8-1=7))=149))=3136)----------------c老去数((169-(15-1-1=13)-(8-1=7))=149)
    16t=12040|a原数(6546)++++++++++b裂变数((6546-((572-(50-4-2=44)-(27-2-1=24))=504)-((311-(27-2-1=24)-(15-1-1=13))=274))=5768)------------c老去数((311-(27-2-1=24)-(15-1-1=13))=274)
    17t=22145|a原数(12040)+++++++++b裂变数((12040-((1052-((92-(8-1=7)-4)=81)-(50-4-2=44))=927)-((572-(50-4-2=44)-(27-2-1=24))=504))=10609)-c老去数((572-(50-4-2=44)-(27-2-1=24))=504)
    重新审查又发现错误,重新推演逻辑和计算,相信这次逻辑和计算是正确的,请不吝赐教.
    公式:t=a+b-c.(b当天实际参与裂变数=a-前4天b这天同时产生裂变数当天不参与裂变-前5天b产生的数但当天不参与裂变).
    以上推演假设裂变时间为0时,然而头5天不能用递归,如果这个推理计算没错的话,可以写代码了。
      

  10.   

    递归,我最拿手了,呵呵        int endTime = 17;        private int cellula(int nowTime)
            {
                int number = 0;
                int getNowTime = nowTime;
                if (endTime - nowTime > 4)
                {
                    number += cellula(++getNowTime) + cellula(++getNowTime) + cellula(++getNowTime);
                }
                else if (endTime - nowTime < 2)
                {
                    number = 1;
                }
                else
                {
                    for (int i = 0; i < endTime - nowTime; i++)
                    {
                        number += cellula(++getNowTime);
                    }
                }
                return number;
            }
    然后直接调用  cellula(0) 就行了
      

  11.   

    最后的循环改为独立判断,细胞产生
    第二天number += cellula(++getNowTime)
    第三天number += cellula(++getNowTime) +cellula(++getNowTime)
    第四天number += cellula(++getNowTime) +cellula(++getNowTime)
    + cellula(++getNowTime)
    第五天 number += cellula(++getNowTime) +cellula(++getNowTime)
    + cellula(++getNowTime)+1
    这样就差不多了。
      

  12.   

    哈哈,终于忍不住手痒,还是写了个递归,这是第二次玩递归写法(第一次学的,这次自己写的),我知道写得不好,比不得诸高手,献丑了.        细胞分裂 细胞分裂信息 = new 细胞分裂();
            List<细胞分裂> 分裂存储 = new List<细胞分裂>();
            private int 细胞分裂递归演算(int 细胞数, int 天数)
            {
                细胞分裂信息.a原数值 = 细胞数; 细胞分裂信息.t天数值++;
                if (细胞分裂信息.t天数值 >= 8)
                { 分裂存储.RemoveAt(0); 细胞分裂信息.数组值 = 7;/*细胞分裂存储.Skip<细胞分裂>(1);*/}
                else 细胞分裂信息.数组值 = 细胞分裂信息.t天数值;
                if (细胞分裂信息.t天数值 >= 5)
                    细胞分裂信息.d不裂值 = (细胞分裂信息.t天数值 == 5) ? 分裂存储[0].a原数值 : 分裂存储[细胞分裂信息.数组值 - 5].b裂数值;
                if (细胞分裂信息.t天数值 >= 6)
                    细胞分裂信息.c老数值 = (细胞分裂信息.t天数值 == 6) ? 分裂存储[0].a原数值 : 分裂存储[细胞分裂信息.数组值 - 6].b裂数值;
                if (细胞分裂信息.t天数值 > 1)
                {
                    细胞分裂信息.b裂数值 = 细胞分裂信息.a原数值 - 细胞分裂信息.d不裂值 - 细胞分裂信息.c老数值;
                    细胞数 = 细胞分裂信息.a原数值 + 细胞分裂信息.b裂数值 - 细胞分裂信息.c老数值;
                }
                细胞分裂 细胞分裂 = new 细胞分裂();
                细胞分裂.a原数值 = 细胞分裂信息.a原数值; 细胞分裂.b裂数值 = 细胞分裂信息.b裂数值;
                细胞分裂.c老数值 = 细胞分裂信息.c老数值; 细胞分裂.d不裂值 = 细胞分裂信息.d不裂值;
                细胞分裂.t天数值 = 细胞分裂信息.t天数值;
                分裂存储.Add(细胞分裂);
                if (细胞分裂信息.t天数值 < 天数) 细胞分裂递归演算(细胞数, 天数);
                if (细胞数 > 细胞分裂信息.总值) 细胞分裂信息.总值 = 细胞数;
                return 细胞分裂信息.总值;
            }        private class 细胞分裂
            {
                public int 数组值 { get; set; }
                public int 总值 { get; set; }
                public int d不裂值 { get; set; }
                public int a原数值 { get; set; }
                public int b裂数值 { get; set; }
                public int c老数值 { get; set; }
                public int t天数值 { get; set; }
            }