結果が勝ち負け(確率1/2)のゲームをn人の総当りリーグ戦で行うとき、単独優勝者が出る確率をnで表せ。
"
rm(list=ls())

sim <- function(n){
games=t(combn(n,2)) # combinations of match
nc=nrow(games) # number of combinations
winner=rbinom(nc,1,0.5)+1 # index of the winner 1 or 2
re=NULL # sequence of winners
for(i in 1:nc) re=c(re,games[i,winner[i]])
tbl=table(re)
sum(tbl==max(tbl))==1 # only one maximum?
}
f <- function(n,k=1e5) mean(replicate(k,sim(n)))
n=2:20
y=sapply(n,f)
plot(n,y,bty='l',pch=19,ylim=c(0,1),ylab='Prob')