http://community.csdn.net/Expert/topic/5641/5641460.xml?temp=.7341883
http://community.csdn.net/Expert/topic/5641/5641458.xml?temp=.8028681我强调一下:不是数到谁杀谁,是数到谁之后杀第一个
所以幸存者绝对不可能是第一个
可以用人数为6,计数为2来测试

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication11
    {
        class Program
        {
                static int LeftManNumber(int n, int m)
                {
                    //建立一个n位每个元素都为false的数组
                    bool[] nums = new bool[n];
                    //索引初始化为0,计数初始化为0,折返标志
                    int index = 0, count = 0, flag = 1;
                    //顺时针移动标志,true表示顺时针移动
                    bool direct = true;
                    //直到数组里只剩下一个1(即第一个1的索引位置和最后一个相同)
                    while (Array.IndexOf(nums, false) != Array.LastIndexOf(nums, false))
                    {
                        //判断第一次数的方向,并赋值
                        if (count == 0)
                        {
                            if (flag == 1)
                                direct = true;
                            if (flag == -1)
                                direct = false;
                        }
                        //第一次第一位肯定有人,所以加1,后面出来肯定有人,所以也加加
                        count++;
                        //如果计数等于m时,此人被踢出,此位置变成0,计数器清0
                        if (count == m)
                        {
                            //如果一开始是顺时针,杀掉最左端的人,逆时针反之
                            if (direct)
                            {
                                Console.WriteLine("本次出圈者编号:{0}", Array.IndexOf(nums, false) + 1);
                                nums[Array.IndexOf(nums, false)] = true;
                            }
                            else
                            {
                                Console.WriteLine("本次出圈者编号:{0}", Array.LastIndexOf(nums, false) + 1);
                                nums[Array.LastIndexOf(nums, false)] = true;
                            }
                            count = 0;
                        }
                        //获取第一个人和最后一个人的编号
                        int thelast = Array.LastIndexOf(nums, false);
                        int thefirst = Array.IndexOf(nums, false);
                        do
                        {
                            //根据标志,前进或者向后退一格
                            index += flag;
                            //如果索引到尾
                            if (index > thelast)
                            {
                                if (index == thelast + 1)
                                    count--;
                                index = thelast;
                                flag = -flag;
                            }
                            //如果索引到头
                            if (index < thefirst)
                            {
                                if (index == thefirst - 1)
                                    count--;
                                index = thefirst;
                                flag = -flag;
                            }
                        }
                        //移动索引位置,直到有人
                        while (nums[index]);                }
                    return Array.IndexOf(nums, false) + 1;
                }
            static void Main(string[] args)
            {
                Console.WriteLine("\n最后的幸存者是:{0}", LeftManNumber(6, 2));
            }
        }
    }
    根据楼主要求改的,上面都加了注释了,自己试试吧,觉得可以的话,100分哦:)
      

  2.   

    viena() 维也纳() ------------你真是姐姐!!
    上海的? 
     
        
      

  3.   

    viena() 维也纳() 是版主?
      

  4.   

    viena() 维也纳() 是姐姐?