【学习资料】袋中共36个球,红白黑格12个,问能一次抽到3个红4个白5个黑的概率是多少?

news2024/9/21 8:34:29

1、公式计算

1.1 题目1

袋中共 36 36 36个球, 红 \fcolorbox{red}{#FADADE}{\color{red}{红}} 白 \fcolorbox{white}{#808080}{\color{white}{白}} 黑 \fcolorbox{#808080}{#0D0D0D}{\color{#808080}{黑}} 12 12 12个,问能一次抽到 3个红 \fcolorbox{red}{#FADADE}{\color{red}{3个红}} 3个红 4个白 \fcolorbox{white}{#808080}{\color{white}{4个白}} 4个白 5个黑 \fcolorbox{#808080}{#0D0D0D}{\color{#808080}{5个黑}} 5个黑的概率是多少?

P m r , m w , m b = C n r m r × C n w m w × C n b m b C n m P_{m_r,m_w,m_b} = \frac{C_{n_r}^{m_r} \times C_{n_w}^{m_w} \times C_{n_b}^{m_b} }{C_{n}^{m}} Pmr,mw,mb=CnmCnrmr×Cnwmw×Cnbmb
其中:
P m r , m w , m b P_{m_r,m_w,m_b} Pmr,mw,mb – 概率
C n m C_{n}^{m} Cnm – n个球中,抽m个球的组合数。
C n r m r C_{n_r}^{m_r} Cnrmr n r n_r nr个红球中,抽 m r m_r mr个红球的组合数。
C n w m w C_{n_w}^{m_w} Cnwmw n w n_w nw个白球中,抽 m r m_r mr个白球的组合数。
C n b m b C_{n_b}^{m_b} Cnbmb n b n_b nb个黑球中,抽 m b m_b mb个黑球的组合数。

根据已知条件代入公式:
已知条件 { n r = 12 n w = 12 n b = 12 m r = 3 m w = 4 m b = 5 n = 36 m = 12 已知条件 \begin{cases} n_r=12 \\ n_w=12 \\ n_b=12 \\ m_r=3 \\ m_w=4 \\ m_b=5 \\ n=36 \\ m=12 \\ \end{cases} 已知条件 nr=12nw=12nb=12mr=3mw=4mb=5n=36m=12

P 3 r , 4 w , 5 b = C 12 3 × C 12 4 × C 12 5 C 36 12 = 12 ! 3 ! × ( 12 − 3 ) ! × 12 ! 4 ! × ( 12 − 4 ) ! × 12 ! 5 ! × ( 12 − 5 ) ! 36 ! 12 ! × ( 36 − 12 ) ! = 12 ! 3 ! × 9 ! × 12 ! 4 ! × 8 ! × 12 ! 5 ! × 7 ! 36 ! 12 ! × 24 ! = 12 ! 3 ! × ( 12 − 3 ) ! × 12 ! 4 ! × ( 12 − 4 ) ! × 12 ! 5 ! × ( 12 − 5 ) ! 36 ! 12 ! × ( 36 − 12 ) ! = 479 , 001 , 600 6 × 362 , 880 × 479 , 001 , 600 24 × 40 , 320 × 479 , 001 , 600 120 × 5 , 040 371 , 993 , 326 , 789 , 901 , 217 , 467 , 999 , 448 , 150 , 835 , 200 , 000 , 000 479 , 001 , 600 × 620 , 448 , 401 , 733 , 239 , 439 , 360 , 000 = 220 × 495 × 792 1 , 251 , 677 , 700 = 86 , 248 , 800 1 , 251 , 677 , 700 = 95832 1390753 = 0.06890655637629399325401419231165 \begin{equation} \begin{split} P_{3_r,4_w,5_b} &= \frac{C_{12}^{3} \times C_{12}^{4} \times C_{12}^{5} }{C_{36}^{12}} \\ &=\frac{\frac{12!}{3!\times (12-3)!}\times \frac{12!}{4!\times (12-4)!} \times\frac{12!}{5!\times (12-5)!}}{\frac{36!}{12!\times (36-12)!}} \\ &=\frac{\frac{12!}{3!\times 9!}\times \frac{12!}{4!\times 8!} \times\frac{12!}{5!\times 7!}}{\frac{36!}{12!\times 24!}} \\ &=\frac{\frac{12!}{3!\times (12-3)!}\times \frac{12!}{4!\times (12-4)!} \times\frac{12!}{5!\times (12-5)!}}{\frac{36!}{12!\times (36-12)!}} \\ &=\frac{\frac{479,001,600}{6\times 362,880}\times \frac{479,001,600}{24\times 40,320} \times\frac{479,001,600}{120\times 5,040}}{\frac{371,993,326,789,901,217,467,999,448,150,835,200,000,000}{479,001,600\times 620,448,401,733,239,439,360,000}} \\ &=\frac{ 220 \times 495 \times 792}{1,251,677,700} \\ &=\frac{86,248,800}{1,251,677,700} \\ &=\frac{95832}{1390753} \\ &=0.06890655637629399325401419231165 \end{split} \end{equation} P3r,4w,5b=C3612C123×C124×C125=12!×(3612)!36!3!×(123)!12!×4!×(124)!12!×5!×(125)!12!=12!×24!36!3!×9!12!×4!×8!12!×5!×7!12!=12!×(3612)!36!3!×(123)!12!×4!×(124)!12!×5!×(125)!12!=479,001,600×620,448,401,733,239,439,360,000371,993,326,789,901,217,467,999,448,150,835,200,000,0006×362,880479,001,600×24×40,320479,001,600×120×5,040479,001,600=1,251,677,700220×495×792=1,251,677,70086,248,800=139075395832=0.06890655637629399325401419231165

1.2 题目2

袋中共 36 36 36 个球, 红 \fcolorbox{red}{#FADADE}{\color{red}{红}} 白 \fcolorbox{white}{#808080}{\color{white}{白}} 黑 \fcolorbox{#808080}{#0D0D0D}{\color{#808080}{黑}} 12 12 12个,问能一次抽到颜色组合是 3 3 3 4 4 4 5 5 5 的概率是多少?

P m 1 , m 2 , m 3 = N ! N 1 ! × N 2 ! × … × N k ! × C n 1 m 1 × C n 2 m 2 × C n 3 m 3 C n m P_{m_1,m_2,m_3} =\frac{N!}{N_1! \times N_2! \times \ldots \times N_k!} \times \frac{C_{n_1}^{m_1} \times C_{n_2}^{m_2} \times C_{n_3}^{m_3} }{C_{n}^{m}} Pm1,m2,m3=N1!×N2!××Nk!N!×CnmCn1m1×Cn2m2×Cn3m3
其中:
P m 1 , m 2 , m 3 P_{m_1,m_2,m_3} Pm1,m2,m3 – 概率
C n m C_{n}^{m} Cnm – n个球中,抽m个球的组合数。
C n 1 m 1 C_{n_1}^{m_1} Cn1m1 n 1 n_1 n1个颜色1球中,抽 m 1 m_1 m1个颜色1球的组合数。
C n 2 m 2 C_{n_2}^{m_2} Cn2m2 n 2 n_2 n2个颜色2球中,抽 m 2 m_2 m2个颜色2球的组合数。
C n 3 m 3 C_{n_3}^{m_3} Cn3m3 n 3 n_3 n3个颜色3球中,抽 m 3 m_3 m3个颜色3球的组合数。
N ! N 1 ! × N 2 ! × … × N k ! \frac{N!}{N_1! \times N_2! \times \ldots \times N_k!} N1!×N2!××Nk!N! m 1 、 m 2 、 m 3 m_1、m_2、m_3 m1m2m3数的排列组合数。

m 1 、 m 2 、 m 3 m_1、m_2、m_3 m1m2m3 N ! N 1 ! × N 2 ! × … × N k ! \frac{N!}{N_1! \times N_2! \times \ldots \times N_k!} N1!×N2!××Nk!N!排列组合
3,4,5第1个数3出现1次
第2个数4出现1次
第3个数5出现1次
3 ! 1 ! × 1 ! × 1 ! \frac{3!}{1! \times 1!\times 1!} 1!×1!×1!3!
3,4,5
3,5,4
4,3,5
4,5,3
5,4,3
5,3,4
4,4,4第1个数4出现3次
3 ! 3 ! \frac{3!}{3!} 3!3!
4,4,4
3,3,6第1个数3出现2次
第2个数6出现1次
3 ! 2 ! × 1 ! \frac{3!}{2! \times 1!} 2!×1!3!
3,3,6
3,6,3
6,3,3
1,1,10第1个数1出现2次
第2个数10出现1次
3 ! 2 ! × 1 ! \frac{3!}{2! \times 1!} 2!×1!3!
1,1,10
1,10,1
10,1,1
… \ldots … \ldots … \ldots

根据已知条件代入公式:
已知条件 { n 1 = 12 n 2 = 12 n 3 = 12 m 1 = 3 m 2 = 4 m 3 = 5 n = 36 m = 12 N = 3 N 1 ( 3 ) = 1 N 2 ( 4 ) = 1 N 3 ( 5 ) = 1 已知条件 \begin{cases} n_1=12 \\ n_2=12 \\ n_3=12 \\ m_1=3 \\ m_2=4 \\ m_3=5 \\ n=36 \\ m=12 \\ N=3\\ N_{1(3)}=1\\ N_{2(4)}=1\\ N_{3(5)}=1\\ \end{cases} 已知条件 n1=12n2=12n3=12m1=3m2=4m3=5n=36m=12N=3N1(3)=1N2(4)=1N3(5)=1

P 3 , 4 , 5 = 3 ! 1 ! × 1 ! × 1 ! × C 12 3 × C 12 4 × C 12 5 C 36 12 = 6 1 × 12 ! 3 ! × ( 12 − 3 ) ! × 12 ! 4 ! × ( 12 − 4 ) ! × 12 ! 5 ! × ( 12 − 5 ) ! 36 ! 12 ! × ( 36 − 12 ) ! = 6 × 12 ! 3 ! × 9 ! × 12 ! 4 ! × 8 ! × 12 ! 5 ! × 7 ! 36 ! 12 ! × 24 ! = 6 × 12 ! 3 ! × ( 12 − 3 ) ! × 12 ! 4 ! × ( 12 − 4 ) ! × 12 ! 5 ! × ( 12 − 5 ) ! 36 ! 12 ! × ( 36 − 12 ) ! = 6 × 479 , 001 , 600 6 × 362 , 880 × 479 , 001 , 600 24 × 40 , 320 × 479 , 001 , 600 120 × 5 , 040 371 , 993 , 326 , 789 , 901 , 217 , 467 , 999 , 448 , 150 , 835 , 200 , 000 , 000 479 , 001 , 600 × 620 , 448 , 401 , 733 , 239 , 439 , 360 , 000 = 6 × 220 × 495 × 792 1 , 251 , 677 , 700 = 6 × 86 , 248 , 800 1 , 251 , 677 , 700 = 6 × 95832 1390753 = 574992 1390753 = 0.41343933825776395952408515386988 \begin{equation} \begin{split} P_{3,4,5} &=\frac{3!}{1! \times 1!\times 1!}\times \frac{C_{12}^{3} \times C_{12}^{4} \times C_{12}^{5} }{C_{36}^{12}} \\ &=\frac{6}{1}\times\frac{\frac{12!}{3!\times (12-3)!}\times \frac{12!}{4!\times (12-4)!} \times\frac{12!}{5!\times (12-5)!}}{\frac{36!}{12!\times (36-12)!}} \\ &=6\times \frac{\frac{12!}{3!\times 9!}\times \frac{12!}{4!\times 8!} \times\frac{12!}{5!\times 7!}}{\frac{36!}{12!\times 24!}} \\ &=6\times \frac{\frac{12!}{3!\times (12-3)!}\times \frac{12!}{4!\times (12-4)!} \times\frac{12!}{5!\times (12-5)!}}{\frac{36!}{12!\times (36-12)!}} \\ &=6\times \frac{\frac{479,001,600}{6\times 362,880}\times \frac{479,001,600}{24\times 40,320} \times\frac{479,001,600}{120\times 5,040}}{\frac{371,993,326,789,901,217,467,999,448,150,835,200,000,000}{479,001,600\times 620,448,401,733,239,439,360,000}} \\ &=6\times \frac{ 220 \times 495 \times 792}{1,251,677,700} \\ &=6\times \frac{86,248,800}{1,251,677,700} \\ &=6\times \frac{95832}{1390753} \\ &=\frac{ 574992}{1390753} \\ &=0.41343933825776395952408515386988 \end{split} \end{equation} P3,4,5=1!×1!×1!3!×C3612C123×C124×C125=16×12!×(3612)!36!3!×(123)!12!×4!×(124)!12!×5!×(125)!12!=6×12!×24!36!3!×9!12!×4!×8!12!×5!×7!12!=6×12!×(3612)!36!3!×(123)!12!×4!×(124)!12!×5!×(125)!12!=6×479,001,600×620,448,401,733,239,439,360,000371,993,326,789,901,217,467,999,448,150,835,200,000,0006×362,880479,001,600×24×40,320479,001,600×120×5,040479,001,600=6×1,251,677,700220×495×792=6×1,251,677,70086,248,800=6×139075395832=1390753574992=0.41343933825776395952408515386988

2、枚举法

使用程序模拟每一次抽取,计算每一步的概率,并进行累计汇总。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static GL39_9.Program;

namespace GL39_9
{
    internal class Program
    {
        /// <summary>
        /// 汇总类型
        /// </summary>
        public enum eSummaryType
        {
            /// <summary>
            /// 按数量汇总
            /// </summary>
            Number,
            /// <summary>
            /// 按名称和数量汇总
            /// P(36,12(3,4,5))=N! * C(12,3)*C(12,4)*C(12,5)/C(36,12)
            /// C(12,3) = 12!/(3!*(12-3)!) = 12!/(3!*9!)
            /// C(12,4) = 12!/(4!*(12-4)!) = 12!/(4!*8!)
            /// C(12,4) = 12!/(5!*(12-5)!) = 12!/(5!*7!)
            /// 3 4 5 (N=3)
            /// 4 4 4 (N=1)
            /// 3 3 6 (N=2)
            /// </summary>
            NameNumber
        }

        public static double Calc(int[] keys,int pre=12)
        {

            int nType = keys.GroupBy(o=>o).Count();
            BigInteger FT = Factorial(nType);
            int t = pre * keys.Count();
            int c = keys.Sum(o=>o);
            BigInteger fz = 1;
            foreach (var item in keys)
            {
                fz *= C(pre, item);
            }
            BigInteger fm = C(t,c);
            return ((double)(long)FT * ((double)(long)fz / (double)(long)fm));
        }
        public static BigInteger C(int n,int m)
        {
            var fn = Factorial(n);
            var fm = Factorial(m);
            var fmn = Factorial(n-m);
            return fn /(fm * fmn);
        }
        public static BigInteger Factorial(int n)
        {
            if (n < 0) throw new ArgumentException("n must be non-negative.");
            if (n == 0) return 1;
            return n * Factorial(n - 1);
        }
        /// <summary>
        /// 暗盒/袋中的物品信息
        /// </summary>
        public class CBlackBoxItem
        {
            /// <summary>
            /// 物品唯一编号
            /// </summary>
            public int Id { get; set; }
            /// <summary>
            /// 物品名称
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 物品数量
            /// </summary>
            public int Number { get; set; }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="id">物品唯一编号</param>
            /// <param name="name">物品名称</param>
            /// <param name="number">物品数量</param>
            public CBlackBoxItem(int id, string name, int number)
            {
                Id = id;
                Name = name;
                Number = number;
            }
            /// <summary>
            /// 物品信息
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return $"{Id}.{Name} {Number}个";
            }
            /// <summary>
            /// 复制物品信息及数量
            /// </summary>
            /// <returns></returns>
            public CBlackBoxItem Copy()
            {
                return new CBlackBoxItem(Id, Name, Number);
            }
            /// <summary>
            /// 复制物品并减去指定数量的物品
            /// </summary>
            /// <param name="val"></param>
            /// <returns></returns>
            public CBlackBoxItem CopySub(int val)
            {
                return new CBlackBoxItem(Id, Name, Number - val);
            }
            /// <summary>
            /// 复制物品并设置数量
            /// </summary>
            /// <param name="val"></param>
            /// <returns></returns>
            public CBlackBoxItem Copy(int val)
            {
                return new CBlackBoxItem(Id, Name, val);
            }
        }
        /// <summary>
        /// 轮次信息
        /// </summary>
        public class CRoundInformation
        {
            /// <summary>
            /// 前一轮的信息
            /// </summary>
            public CRoundInformation previousRound = null;
            /// <summary>
            /// 本轮暗箱信息
            /// </summary>
            public List<CBlackBoxItem> CurrentRoundBlackBox = new List<CBlackBoxItem> {
                new CBlackBoxItem(1,"红色球/棍子",9),
                new CBlackBoxItem(2,"绿色球/棍子",9),
                new CBlackBoxItem(3,"蓝色球/棍子",9),
            };

            /// <summary>
            /// 从暗盒中获取总数量
            /// </summary>
            /// <returns></returns>
            public int GetTotalNumberFromBlackBox()
            {
                return CurrentRoundBlackBox.Select(o => o.Number).Sum();
            }
            /// <summary>
            /// 当前从暗箱中抽中的物品
            /// </summary>
            public CBlackBoxItem CurrentDrawnBlackBoxItem = null;
            /// <summary>
            /// 当前轮次概率
            /// </summary>
            public double CurrentRoundProbability = 0;
            /// <summary>
            /// 累计所有轮的概率
            /// </summary>
            public double CumulativeProbability = 0;
            /// <summary>
            /// 累计所有抽到的物品
            /// </summary>
            public List<CBlackBoxItem> CumulativeDrawnBlackBoxItems = new List<CBlackBoxItem>();
            /// <summary>
            /// 所有抽到的物品归类信息
            /// </summary>
            public string SummaryInformation = "";
            /// <summary>
            /// 轮次
            /// </summary>
            public int RoundIndex = 0;
            /// <summary>
            /// 更新累计的概率
            /// </summary>
            public void UpdateCumulativeProbability()
            {
                double probability = 1.0;
                GetCumulativeProbability(this, ref probability);
                CumulativeProbability = probability;
            }
            /// <summary>
            /// 递归获取累计概率
            /// </summary>
            /// <param name="roundInformation"></param>
            /// <param name="probability"></param>
            private void GetCumulativeProbability(CRoundInformation roundInformation, ref double probability)
            {
                if (roundInformation == null) return;
                if (roundInformation.RoundIndex <= 0) return;
                probability *= roundInformation.CurrentRoundProbability;
                GetCumulativeProbability(roundInformation.previousRound, ref probability);
            }
           
            /// <summary>
            /// 统计抽到的物品,获取汇总信息
            /// </summary>
            public void UpdateDrawnBlackBoxItems(eSummaryType summaryType = eSummaryType.Number)
            {
                List<CBlackBoxItem> blackBoxItems = new List<CBlackBoxItem>();
                GetDrawnBlackBoxItems(this, ref blackBoxItems);

                CumulativeDrawnBlackBoxItems = blackBoxItems;
                List<CBlackBoxItem> temps = new List<CBlackBoxItem>();
                foreach (var item in CurrentRoundBlackBox)
                {
                    temps.Add(item.Copy(blackBoxItems.Where(o => o.Id == item.Id).Count()));
                }
                temps = temps.OrderByDescending(o => o.Number).ToList();
                if(summaryType == eSummaryType.Number)
                {
                    SummaryInformation = string.Join(":", temps.Select(o => o.Number));
                }
                else if (summaryType == eSummaryType.NameNumber)
                {
                    SummaryInformation = string.Join(":", temps.Select(o => o.Number)) +"|" + string.Join(":", temps);
                }
            }
            /// <summary>
            /// 递归获取每一轮的物品
            /// </summary>
            /// <param name="roundInformation"></param>
            /// <param name="blackBoxItems"></param>
            private void GetDrawnBlackBoxItems(CRoundInformation roundInformation, ref List<CBlackBoxItem> blackBoxItems)
            {
                if (roundInformation == null) return;
                if (roundInformation.RoundIndex <= 0) return;
                blackBoxItems.Add(roundInformation.CurrentDrawnBlackBoxItem);
                GetDrawnBlackBoxItems(roundInformation.previousRound, ref blackBoxItems);
            }
            /// <summary>
            /// 从暗盒中抽一个物品
            /// </summary>
            /// <param name="roundIndex"></param>
            /// <returns></returns>
            public List<CRoundInformation> DrawnOneItemFromBlackBox(int roundIndex)
            {
                List<CRoundInformation> roundInformations = new List<CRoundInformation>();
                var total = GetTotalNumberFromBlackBox();
                foreach (var item in CurrentRoundBlackBox)
                {
                    if (item.Number <= 0)
                    {
                        continue;
                    }
                    CRoundInformation roundInformation = new CRoundInformation();
                    roundInformation.RoundIndex = roundIndex;
                    roundInformation.previousRound = this;
                    roundInformation.CurrentDrawnBlackBoxItem = new CBlackBoxItem(item.Id, item.Name, 1);
                    roundInformation.CurrentRoundProbability = item.Number / (double)total;
                    roundInformation.CurrentRoundBlackBox.Clear();
                    foreach (var itme in CurrentRoundBlackBox)
                    {
                        if (item.Id == itme.Id)
                        {
                            roundInformation.CurrentRoundBlackBox.Add(itme.CopySub(1));
                        }
                        else
                        {
                            roundInformation.CurrentRoundBlackBox.Add(itme.Copy());
                        }
                    }
                    roundInformations.Add(roundInformation);
                }
                return roundInformations;
            }
        }

        /// <summary>
        /// 概率小游戏
        /// </summary>
        public class CProbabilityGame
        {
            public List<CRoundInformation> Source = new List<CRoundInformation>();
            public int DrawnTimes = 9;
            /// <summary>
            /// 每次抽取花费
            /// 100块抽5次
            /// </summary>
            public double SpendEveryTime = 20;
            public eSummaryType SummaryType =   eSummaryType.Number;

            /// <summary>
            /// 奖池
            /// </summary>
            public Dictionary<string, double> Jackpots = new Dictionary<string, double>
            {
                {"9:0:0",100},//:  0.000640092173272951‰
                {"8:1:0",30},//:  0.103694932070218‰
                {"7:2:0",10},//:  1.65911891312349‰
                {"7:1:1",20},//:  1.86650877726393‰
                {"6:3:0",10},//:  9.03298074922795‰
                {"6:2:1",10},//:  34.8414971755928‰
                {"5:4:0",2},//:  20.3242066857629‰
                {"5:3:1",2},//:  121.945240114572‰
                {"5:2:2",1},//:  104.524491526778‰
                {"4:4:1",1},//:  91.4589300859336‰
                {"4:3:2",-10},//:  487.780960458368‰
                {"3:3:3",1}//:  126.461730489187‰
            };
            public CProbabilityGame()
            {
                //Init312Drawn12();
                Init39Drawn9();
            }
            /// <summary>
            /// 3 种颜色的物品 每种 12个,抽12个
            /// </summary>
            public void Init312Drawn12()
            {
                DrawnTimes = 12;
                SummaryType = eSummaryType.Number;
                var item = new CRoundInformation();
                item.CurrentRoundBlackBox.Clear();
                item.CurrentRoundBlackBox = new List<CBlackBoxItem> {
                new CBlackBoxItem(1,"红色球/棍子",DrawnTimes),
                new CBlackBoxItem(2,"绿色球/棍子",DrawnTimes),
                new CBlackBoxItem(3,"蓝色球/棍子",DrawnTimes),
                };
                Source.Add(item);
                Jackpots.Clear();
                Jackpots = new Dictionary<string, double>
            {
                {"12:0:0",100},//2.39678313354948E-06‰
                {"11:1:0",30},//0.00069027354246225‰
                {"10:2:0",20},//0.020880774659483‰
                {"10:1:1",20},//0.0227790269012542‰
                {"9:3:0",10},//0.232008607327592‰
                {"9:2:1",10},//0.835230986379351‰
                {"8:4:0",5},//1.17454357459599‰
                {"8:3:1",5},//6.26423239784602‰
                {"8:2:2",5},//5.16799172822235‰
                {"7:5:0",5},//3.0068315509653‰
                {"7:4:1",2},//22.551236632241‰
                {"7:3:2",2},//55.1252451009996‰
                {"6:6:0",5},//2.04631591662927‰
                {"6:5:1",2},//42.0956417134937‰
                {"6:4:2",1},//144.70376839016‰
                {"6:3:3",1},//107.187976585368‰
                {"5:5:2",1},//99.2254411818329‰
                {"5:4:3",-10},//413.439338257532‰
                {"4:4:4",1},//96.8998449041164‰
            };
            }
            /// <summary>
            /// 3 种颜色的物品 每种 9个,抽9个
            /// </summary>
            public void Init39Drawn9()
            {
                DrawnTimes = 9;
                SpendEveryTime = 0.5;
                SummaryType = eSummaryType.Number;
                var item = new CRoundInformation();
                item.CurrentRoundBlackBox.Clear();
                item.CurrentRoundBlackBox = new List<CBlackBoxItem> {
                new CBlackBoxItem(1,"红色球/棍子",DrawnTimes),
                new CBlackBoxItem(2,"绿色球/棍子",DrawnTimes),
                new CBlackBoxItem(3,"蓝色球/棍子",DrawnTimes),
                };
                Source.Add(item);
                Jackpots.Clear();
                Jackpots = new Dictionary<string, double>
            {
                {"9:0:0",100},//:  0.000640092173272951‰
                {"8:1:0",30},//:  0.103694932070218‰
                {"7:2:0",10},//:  1.65911891312349‰
                {"7:1:1",20},//:  1.86650877726393‰
                {"6:3:0",10},//:  9.03298074922795‰
                {"6:2:1",10},//:  34.8414971755928‰
                {"5:4:0",2},//:  20.3242066857629‰
                {"5:3:1",2},//:  121.945240114572‰
                {"5:2:2",1},//:  104.524491526778‰
                {"4:4:1",1},//:  91.4589300859336‰
                {"4:3:2",-10},//:  487.780960458368‰
                {"3:3:3",1}//:  126.461730489187‰
            };
            }
            /// <summary>
            /// 计算
            /// </summary>
            /// <returns></returns>
            public double Calculate()
            {
                List<CRoundInformation> listTemp = new List<CRoundInformation>();
                Drawn(ref listTemp);
                Cumulative(ref listTemp);
                var pro = SummaryProbabilitys(listTemp);
                if(CheckProbabilitys(pro))
                {
                    return CalculateProfitLoss(pro);

                }
                return double.MinValue;
            }
            /// <summary>
            /// 检查概率是否归一
            /// </summary>
            /// <param name="Probabilitys"></param>
            /// <returns></returns>
            public bool CheckProbabilitys(Dictionary<string, double> Probabilitys)
            {
                var val = Probabilitys.Sum(o => o.Value);
                System.Diagnostics.Debug.WriteLine(val);
                if(val>1-0.0000001 && val<1+0.0000001)
                {
                    return true;
                }
                return false;
            }
            /// <summary>
            /// 累计
            /// </summary>
            /// <param name="listTemp"></param>
            private void Cumulative(ref List<CRoundInformation> listTemp)
            {
                foreach (var item in listTemp)
                {
                    item.UpdateCumulativeProbability();
                    item.UpdateDrawnBlackBoxItems(SummaryType);
                }
            }
            /// <summary>
            /// 抽取
            /// </summary>
            /// <param name="listTemp"></param>
            private void Drawn(ref List<CRoundInformation> listTemp)
            {
                listTemp = Source;
                for (int i = 1; i <= DrawnTimes; i++)
                {
                    var temps = new List<CRoundInformation>();
                    foreach (var item in listTemp)
                    {
                        if (item.RoundIndex < i - 1)
                        {
                            continue;
                        }
                        var list = item.DrawnOneItemFromBlackBox(i);
                        temps.AddRange(list);
                    }
                    listTemp = temps;
                }
            }
            /// <summary>
            /// 汇总
            /// </summary>
            /// <param name="listTemp"></param>
            /// <returns></returns>
            private Dictionary<string, double> SummaryProbabilitys(List<CRoundInformation> listTemp)
            {
                Dictionary<string, double> Probabilitys = new Dictionary<string, double>();
                System.Diagnostics.Debug.WriteLine($"|组合|概率");
                System.Diagnostics.Debug.WriteLine($"|--|--|");

                foreach (var item in listTemp.GroupBy(o => o.SummaryInformation).OrderByDescending(o => o.Key))
                {
                    var glall = item.Sum(o => o.CumulativeProbability);
                    Probabilitys.Add(item.Key, glall);
                    System.Diagnostics.Debug.WriteLine($"|{item.Key}|{glall * 100}%");
                    //System.Diagnostics.Debug.WriteLine($"{{\"{item.Key}\",{1.0/ glall}}},//{glall*1000}‰");
                }
                return Probabilitys;
            }

            /// <summary>
            /// 计算盈亏
            /// </summary>
            private double CalculateProfitLoss(Dictionary<string, double> Probabilitys)
            {
                double revenue = -SpendEveryTime;
                foreach (var item in Jackpots)
                {
                    if (Probabilitys.ContainsKey(item.Key))
                    {
                        revenue += Probabilitys[item.Key] * item.Value;
                    }
                }
                return revenue;
            }
            static void Main(string[] args)
            {
                CProbabilityGame game = new CProbabilityGame();
                var item = Program.Calc(new int[3] {3,4,5 },12);
                System.Diagnostics.Debug.WriteLine(item);
                var val = 20 * game.Calculate();
                System.Diagnostics.Debug.WriteLine(val);
            }
            
            
        }
    }
}

3、拓展

街头玩法

在这里插入图片描述
每次费用 10 / 20 = 0.5 元 10/20=0.5元 10/20=0.5
根据概率,抽一次罚 3.7749845577769543 元 3.7749845577769543元 3.7749845577769543
加上成本 0.5 0.5 0.5 ,每把亏 4.2749845577769543 元 4.2749845577769543元 4.2749845577769543
每次交费玩 20 20 20次,一次缴费 4.2749845577769543 × 20 = 85.499691155539086 元 4.2749845577769543\times 20=85.499691155539086元 4.2749845577769543×20=85.499691155539086

常见玩法概率表

3种颜色物品,每种9个,每次抽9个的概率

组合概率
9:0:00.0000640092173272951%
8:1:00.0103694932070218%
7:2:00.165911891312349%
7:1:10.186650877726393%
6:3:00.903298074922795%
6:2:13.48414971755928%
5:4:02.03242066857629%
5:3:112.1945240114572%
5:2:210.4524491526778%
4:4:19.14589300859336%
4:3:248.7780960458368%
3:3:312.6461730489187%

3种颜色物品,每种12个,每次抽12个的概率

组合概率
12:0:00.000000239678313354948%
11:1:00.000069027354246225%
10:2:00.0020880774659483%
10:1:10.00227790269012542%
9:3:00.0232008607327592%
9:2:10.0835230986379351%
8:4:00.117454357459599%
8:3:10.626423239784602%
8:2:20.516799172822235%
7:5:00.30068315509653%
7:4:12.2551236632241%
7:3:25.51252451009996%
6:6:00.204631591662927%
6:5:14.20956417134937%
6:4:214.470376839016%
6:3:310.7187976585368%
5:5:29.92254411818329%
5:4:341.3439338257532%
4:4:49.68998449041164%

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2146858.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

事件循环异步代码输出顺序题目【基础考核】

简单的事件循环&#xff0c;一道异步代码执行输出顺序问题? 第一题 setTimeout(() > {console.log("A")Promise.resolve().then(() > { console.log("B"); });}, 1000);Promise.resolve().then(() > { console.log("c"); });new Prom…

JSON.parseArray 内存溢出

实际上我的JSON如下&#xff1a; 如果用以下代码&#xff1a;JVM的内存直接飙到内存溢出&#xff0c;报错OutOfMemoryError: Java heap space Object oo JSON.parseArray(json, TestVo.class) 如果我换成了这样&#xff0c;就没事&#xff1a; Object oo JSON.parseObject(…

1.2 测试基础

欢迎大家订阅【软件测试】 专栏&#xff0c;开启你的软件测试学习之旅&#xff01; 文章目录 前言1 测试分类1.1 按生产阶段划分1.2 按代码可见度划分1.3 其他测试 2 质量模型 前言 在软件开发过程中&#xff0c;测试是确保产品质量的重要环节。本文详细讲解了软件测试分类以及…

Python Email库:发送与接收邮件完整指南!

Python Email库如何集成&#xff1f;怎么优化Python Email库性能&#xff1f; Python作为一种强大的编程语言&#xff0c;提供了丰富的库来处理电子邮件&#xff0c;其中最著名的就是Python Email库。AokSend将深入探讨如何使用Python Email库来发送和接收邮件&#xff0c;帮助…

SpringCloud config native 配置

SpringCloud config native 配置 1.概述 最近项目使用springCloud 框架&#xff0c;使用config搭建git作为配置中心。 在私有化部署中&#xff0c;出现很多比较麻烦的和鸡肋的设计。 每次部署都需要安装gitlab 有些环境安装完gitlab&#xff0c;外面不能访问&#xff0c;不给开…

适合运动的骨传导耳机哪款好?分享五款性能卓越骨传导耳机

面对琳琅满目的骨传导耳机市场&#xff0c;是不是既兴奋又迷茫&#xff1f;别怕&#xff0c;我来给你支几招&#xff01;选耳机&#xff0c;最重要的是适合自己&#xff0c;别被各种噱头和价格差异绕晕了头。价格高低与品质好坏并非绝对正比&#xff0c;关键看性价比和个人需求…

Google SERP API 对接说明

Google SERP API 对接说明 Google SERP&#xff08;Search Engine Results Page&#xff09;是用户在Google搜索引擎中输入查询后看到的结果页面。它显示自然搜索结果、广告、特色摘要、知识图谱以及图片、视频等多种内容&#xff0c;旨在为用户提供最相关的信息。 本文将详细…

物联网开发+充电桩管理系统+充电桩系统源码

简述 SpringBoot 框架&#xff0c;充电桩平台充电桩系统充电平台充电桩互联互通协议云快充协议1.5新能源汽车电动自行车公交车-四轮车充电充电源代码充电平台源码Java源码无加密项目 介绍 云快充协议云快充1.5协议云快充协议开源代码云快充底层协议云快充桩直连桩直连协议充…

鸿蒙应用生态构建的核心目标

保护开发者和用户利益的同时维护整体系统的安全性&#xff0c;对生态构建者是至关重要的。以开发者为中心&#xff0c;构建端到端应用安全能力&#xff0c;保护应用自身安全、运行时安全&#xff0c;保障开发者权益&#xff0c;是鸿蒙应用生态构建的核心目标。 应用生命周期主要…

大数据-137 - ClickHouse 集群 表引擎详解2 - MergeTree 存储结构 一级索引 跳数索引

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; 目前已经更新到了&#xff1a; Hadoop&#xff08;已更完&#xff09;HDFS&#xff08;已更完&#xff09;MapReduce&#xff08;已更完&am…

CAD图1

文章目录 选择直线工具选择圆形选中圆形 选择直线工具 画一条十字中心线 选择圆形 以十字中心为起点画一个半径为 53 的圆形 选中圆形 选中圆形&#xff0c;捕捉右侧圆形焦点

【北京迅为】《STM32MP157开发板使用手册》- 第四十章 二值信号量实验

iTOP-STM32MP157开发板采用ST推出的双核cortex-A7单核cortex-M4异构处理器&#xff0c;既可用Linux、又可以用于STM32单片机开发。开发板采用核心板底板结构&#xff0c;主频650M、1G内存、8G存储&#xff0c;核心板采用工业级板对板连接器&#xff0c;高可靠&#xff0c;牢固耐…

②MODBUS TCP 转 RS485(RS485与TCP数据双向互传)MODBUS TCP与MODBUS RTU互转(无需编程 独立通道)

型号&#xff1a;1路总线TCP网关&#xff08;单网口&#xff09; MS-A1-5011 1路总线TCP网关&#xff08;双网口&#xff09; MS-A2-5011 2路总线TCP网关&#xff08;单网口&#xff09; MS-A1-5021 2路总线TCP网关&#xff08;双网口&#xff09; MS-A2-5021 4路总…

怎样把PPT上顽固的图标删了

例如&#xff1a; 解决&#xff1a; 首先打开下载好的PPT模板&#xff0c;然后在视图选项卡里面找到幻灯片母版。 进入幻灯片母版后&#xff0c;找到第一页母版页就会看到LOGO了&#xff0c;这时使用鼠标就可以选中删除啦。

【Web】从网安的角度浅聊Groovy命令执行

什么是 Groovy&#xff1f; Groovy 是一种基于 Java 平台的动态语言&#xff0c;旨在提高开发效率。它与 Java 语言高度兼容&#xff0c;允许开发者以更简洁的方式编写代码。Groovy 支持面向对象编程、闭包、DSL&#xff08;领域特定语言&#xff09;等特性&#xff0c;使得它…

OpenHarmony(鸿蒙南向开发)——标准系统方案之瑞芯微RK3566移植案例(上)

往期知识点记录&#xff1a; 鸿蒙&#xff08;HarmonyOS&#xff09;应用层开发&#xff08;北向&#xff09;知识点汇总 鸿蒙&#xff08;OpenHarmony&#xff09;南向开发保姆级知识点汇总~ OpenHarmony&#xff08;鸿蒙南向开发&#xff09;——轻量系统STM32F407芯片移植案…

Eclipse离线安装Tomcat插件

Eclipse离线安装Tomcat插件 最近的自己在对低版本的代码的进行维护补丁,不得不采用Eclipse 来进行跑项目,真的是折磨 其中遇到一个问题就是打开Eclipse的2021版,安装Tomcat的插件,发现好家伙,就是死活在线安装失败 (喵的,真的是让我抓耳挠腮!!哈哈哈) 无奈,只好采用离线安装,特…

C# 携手 7-Zip 命令行:大文件压缩的终极武器?

前言 嗨&#xff0c;大家好&#xff01; 今天咱们来聊聊如何用 C# 调用 7-Zip 命令行来压缩大文件&#xff0c;这是个既高效又稳定的好办法&#xff0c;亲测有效&#xff01; 在实际工作中&#xff0c;压缩文件几乎是家常便饭&#xff0c;但可惜的是&#xff0c;许多常用的方…

VBS学习2:问题解决(文件中含义中文运行报错或者中文乱码)

文件中含义中文运行报错或者中文乱码 问题 msgbox"fdsfdsf大蘇打撒旦dsfsdffsdfsd发斯蒂芬斯蒂芬"解决 文件编码修改成GB2312

JAVA开源项目 校园美食分享平台 计算机毕业设计

本文项目编号 T 033 &#xff0c;文末自助获取源码 \color{red}{T033&#xff0c;文末自助获取源码} T033&#xff0c;文末自助获取源码 目录 一、系统介绍二、演示录屏三、启动教程四、功能截图五、文案资料5.1 选题背景5.2 国内外研究现状5.3 可行性分析 六、核心代码6.1 查…