概率统计几道题目
注意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){#regionvar 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){//淘汰Aif (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
總結
- 上一篇: 51个最佳jQuery教程和示例
- 下一篇: 单片机——数码管