概率统计几道题目

注意exactly 表示恰好参加 i场比赛,因此他们之间是不相容的

数字标的是针对月牙形状区域,上一题也类似,所以Ai(i=1,2,3..n) 的确可以分割2^n  -1 场比赛构成的样本空间

        static void T10()
        {

            var listTmp = new List<String>();
            var n=3;
            for (int i = 1; i <= Math.Pow( 2,n); i++)
            {
                listTmp.Add("选手" + i);
            }
            var _TA="选手3";
            var _TB="选手1";
            var total=10000000;
            var rnd = new Random(Environment.TickCount);
            var count=0;
            for (int i = 0; i < total; i++)
            {
                var member = new String[(int)Math.Pow(2, n)];
                listTmp.CopyTo(member);
                var list = new List<String>(member);
                var listNextRound = new List<String>();

                var round = list.Count / 2;
                while (round >0)
                {
                    #region
                    var flag = false;
                   
                    for (int j = 0; j < round; j++)
                    {
                        var indexA = rnd.Next(list.Count);
                        var A = list[indexA];
                        list.RemoveAt(indexA);
                        var indexB = rnd.Next(list.Count);
                        var B = list[indexB];
                        list.RemoveAt(indexB);
                        if (A == _TA && B == _TB)
                        {
                            count++;
                            flag = true;
                            break;
                        }
                        if (A == _TB && B == _TA)
                        {
                            count++;
                            flag = true;
                            break;
                        }
                        var victorMember = A;
                        if (rnd.Next(2) == 1)
                        {
                            //淘汰A
                            if (A == _TA || A == _TB)
                            {
                                //有一个被淘汰了不可能再遇上
                                flag = true;
                                break;
                            }
                            victorMember = B;

                        }

                        listNextRound.Add(victorMember);
                       // Console.WriteLine("{0} VS {1}, {2} Win--R{3}", A, B, victorMember,round);
                        

                    }
                    if (flag) break;
                    list = new List<String>(listNextRound);
                    listNextRound.Clear();
                    round = list.Count / 2;
                    #endregion
                }



            }
            Console.WriteLine("total:{0},count:{1},Percent:{2}", total, count, (double)count /(double) total);
            Console.WriteLine("hope:{0}",Math.Pow(0.5,n-1));
        }
View Code

针对比赛的模拟程序,结果是上面定义的概率是相对于比赛总体次数(不是每次2人对战记一次数)。

假设这比赛一年举行一次,那么A碰到B的概率是 p的情况表面,每100年的100场比赛中有p*100场 A要vsB,这也意味着今年有p的概率A会vsB

原文地址:https://www.cnblogs.com/wdfrog/p/10766320.html