ITPub博客

首页 > 数据库 > Oracle > 棋手的概率问题

棋手的概率问题

原创 Oracle 作者:piliskys 时间:2014-11-15 21:41:46 0 删除 编辑
这是 PUZZLEUP 2014 的15题  ,ITPUB的oracle开发版有一专门的帖子
There are 24 players in a chess tournament. 8 teams participated with 2 players , and 8 teams participated with 1 player. For the 12 matches in the first round, the pairings will be drawn randomly. What is the probability that at least 4 matches will be played between players from the same school?

Enter your answer as a simplified fraction. Example:12/23

棋手

共有24名选手参加国际象棋比赛。 8支队有2名选手参加,8支队以1名选手参加。 在第一轮的12场比赛,选手之间是随机配对的。
至少有四场比赛是在同一个学校的选手之间进行,这样的概率是多少?

将你的答案输入为简化分数,例如:12/23
--------------------------------------------
自我感觉概率统计学的还行,结果弄了半天还是没有推出公式, 最后,写了个穷举法sql来算
  
  1. --24个人
  2.  with a as (select power(2, rownum-1) rn, rownum rnc from dual connect by rownum <=24)
  3.  , b as (select rownum rn, a.rn+b.rn txx ,
  4. --flag为1是同一队
  5. case when b.rnc=a.rnc+1 and b.rnc<=16 and mod(b.rnc,2)=0 then 1 else 0 end flag
  6.    from a, a b where b.rn>a.rn)
  7.  ,d (idx, rn, txx,flag) as
  8. ( select 1 idx, b.rn, b.txx , b.flag from b
  9.     union all
  10.     select d.idx+1, b.rn , d.txx +b.txx txx ,d.flag+b.flag
  11.      from d,b where b.rn>d.rn and bitand(d.txx,b.txx)=0
  12.     )
  13.  --4代表至少4队
  14.  select sum(case when d.flag>=4 then 1 else 0 end) ff, count(1) alll
  15.  ,sum(case when d.flag>=1 then 1 else 0 end) / count(1)
  16.  --12是配成12队的
  17. from d where d.idx=12
  
结果,运行一小时还没有出结果:(
运行到14人就要40来秒了,  有兴趣的,可以推推出公式玩玩

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/134308/viewspace-1334392/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-14

  • 博文量
    68
  • 访问量
    184718