7,774
社区成员




public static int GetCountWG(int y)
{
Func<int, int> GetChildren = year => year < 0 ? 0 : 10 - year;
List<int> wg_list = new List<int>();//记录每个乌龟的年龄
wg_list.Add(0);//初始化一个新生乌龟
for (int i = 0; i < y; i++)
{
GC.Collect();
Console.Write("第{0}年:", i);
List<int> wg_list_new = new List<int>();//此年新生儿
for (int j = 0; j < wg_list.Count; j++)
{
int[] new_wgs = new int[GetChildren(wg_list[j])];
for (int k = 0; k < new_wgs.Length; k++) new_wgs[k] = -10;//10年后才能生
wg_list_new.AddRange(new_wgs);
wg_list[j]++;
if (wg_list[j] > 10)
{
wg_list.RemoveAt(j);
j--;
}
}
wg_list.AddRange(wg_list_new);
Console.WriteLine(wg_list.Count);
}
return wg_list.Count;
}