【高中数学/排列组合/概率】(2022年普通高等学校招生全国统一考试(全国乙卷)第13题)从甲乙丙丁戊五名同学中随机选三名参加社会服务,则甲乙都入选的概率为多少?

【问题】

从甲乙丙丁戊五名同学中随机选三名参加社会服务,则甲乙都入选的概率为多少?

【答案】

3/10

【出处】

2022年普通高等学校招生全国统一考试(全国乙卷)第13题,填空题第一题,5分。

【解答过程】

五抽3是C(5,3)=10,这是总抽法;

从丙丁戊中选一名和甲乙编组,共有三种抽法;

因此甲乙都入选的概率为0.3.

【点评】

送分题,可以心算。

【验证程序】

主类:

package test251122;

import java.util.List;

/**
 * 从甲乙丙丁戊五名同学中随机选三名参加社会服务,则甲乙都入选的概率为多少?
 * 2022年普通高等学校招生全国统一考试(全国乙卷)第13题,填空题第一题,5分。
 *
 */
public class Test {
    public static void main(String[] args) {
        String[] names= {"甲","乙","丙","丁","戊",};
        int[] idxs= {0,1,2,3,4};
        
        Combination c=new Combination(idxs,3);
        List<List<Integer>> results=c.getResults();
        
        System.out.println("总抽法:");
        int idx=0;
        for(List<Integer> res:results) {
            // 获得排列方案
            String order="";
            for(int i=0;i<res.size();i++) {
                order+=names[res.get(i)];
            }                        
            System.out.println(String.format("%02d", ++idx) +"."+order);
        }
        
        System.out.println("\n包含甲乙的抽法:");
        idx=0;
        for(List<Integer> res:results) {
            boolean jiaExist=false;
            boolean yiExist=false;
            for(int sn:res) {
                if(sn==0) {
                    jiaExist=true;
                }
                
                if(sn==1) {
                    yiExist=true;
                }
            }
            
            if(jiaExist && yiExist) {
                // 获得排列方案
                String order="";
                for(int i=0;i<res.size();i++) {
                    order+=names[res.get(i)];
                }
                System.out.println(String.format("%02d", ++idx) +"."+order);
            }
        }
    }
}

选择器类: 

package test251122;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * 数学中排列组合中的组合器实现
 * 传入一个数组及选择的个数,传出所有选择方案
 */
class Combination {
    /**
     * 用于存放中间结果
     */
    private Stack<Integer> stack;
    
    /**
     * 用于存放结果
     */
    private List<List<Integer>> results;
    
    /**
     * 构造函数
     * @param arr 进行组合的元素
     * @param count 选多少个
     */
    public Combination(int[] arr,int count) {
        if(count>arr.length) {
            throw new ArrayIndexOutOfBoundsException(count+">"+arr.length);
        }
        
        stack = new Stack<>();
        results=new ArrayList<>();
        doSelect(arr,count,0,0);
    }
    
    /**
     * 进行选择
     * @param arr 目标数组
     * @param expect 期望选择数量
     * @param actual 实际选择数量
     * @param current 当前下标
     */
    private void doSelect(int[] arr, int expect, int actual, int current) {
        if(actual == expect) {
            List<Integer> list=new ArrayList<>();
            
            for(int i:stack) {
                list.add(i);
            }
            
            results.add(list);
            
            return;
        }
         
        for(int i=current;i<arr.length;i++) {
            if(!stack.contains(arr[i])) {
                stack.add(arr[i]);
                doSelect(arr, expect, actual+1, i);
                stack.pop();
            }
        }
    }
    
    /**
     * 取得组合结果
     * @return
     */
    public List<List<Integer>> getResults(){
        return results;
    }
    
    /**
     * 测试
     * @param args
     */
    public static void main(String[] args) {
        final int[] arr= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
        final int count=2;
        
        Combination c=new Combination(arr,count);
        List<List<Integer>> results=c.getResults();
        
        int idx=0;
        for(List<Integer> res:results) {
            System.out.println(String.format("%02d", ++idx) +"."+res);
        }
    }
}

 

【程序输出结果】

总抽法:
01.甲乙丙
02.甲乙丁
03.甲乙戊
04.甲丙丁
05.甲丙戊
06.甲丁戊
07.乙丙丁
08.乙丙戊
09.乙丁戊
10.丙丁戊

包含甲乙的抽法:
01.甲乙丙
02.甲乙丁
03.甲乙戊

 

END

posted @ 2021-09-20 14:19  逆火狂飙  阅读(192)  评论(0)    收藏  举报