算法第五天-01的概率问题+mysql复习

x33g5p2x  于2022-05-25 转载在 Mysql  
字(0.8k)|赞(0)|评价(0)|浏览(291)

01由不等概率转变为等概率:

package Random.随机函数;

/**
 * 不等概率的01----->等概率01
 */
public class Test2 {

    public  static  int x(){
        return Math.random() < 0.84? 0 : 1;
    }

    /**
     * 等概率的01   先判断一次,ans要是是0,在判断一次,要是还是0,返回0,要是1就重来一次,同理1也这样,01就是等概率
     * @return
     */
    public  static  int y(){
        int ans = 0;
        do {
            ans = x();
        }while (ans==x());
            return  ans;
    }


}

··································································································

········································分割线·················································

··································································································

MYSQL

这个题是三个表,我们的思维就是化成两个表,将其中两个表通过内连接合并,然后再和第一个表左连接查询

SELECT e.last_name, e.first_name, b.dept_name
FROM employees AS e
LEFT JOIN (SELECT d.dept_no,d.dept_name,de.emp_no
FROM departments AS d
INNER JOIN dept_emp AS de
ON d.dept_no=de.dept_no
) AS b
ON e.emp_no=b.emp_no;

相关文章