zoukankan      html  css  js  c++  java
  • CF1392H ZS Shuffles Cards

    Description

    zscoder has a deck of $n+m$ custom-made cards, which consists of $n$ cards labelled from $1$ to $n$ and $m$ jokers. Since zscoder is lonely, he wants to play a game with himself using those cards.

    Initially, the deck is shuffled uniformly randomly and placed on the table. zscoder has a set $S$ which is initially empty.

    Every second, zscoder draws the top card from the deck.

    If the card has a number $x$ written on it, zscoder removes the card and adds $x$ to the set $S$ .
    If the card drawn is a joker, zscoder places all the cards back into the deck and reshuffles (uniformly randomly) the $n+m$ cards to form a new deck (hence the new deck now contains all cards from $1$ to $n$ and the $m$ jokers). Then, if $S$ currently contains all the elements from $1$ to $n$ , the game ends. Shuffling the deck doesn't take time at all.
    What is the expected number of seconds before the game ends? We can show that the answer can be written in the form $frac{P}{Q}$ where $P,Q$ are relatively prime integers and $Q eq 0 mod 998244353$
    Output the value of $(P cdot Q^{-1})$

    Solution

    考虑先计算每一轮摸牌多少次,再考虑期望抽到Joker次数(轮数)

    每一张数字牌在所有Joker前的概率为$frac {1}{m+1}$,所以期望每一轮抽到的数字牌张数为$frac{n}{m+1}+1$

    设$f_k$为还剩$k$个数没有进入集合时的期望步数,有

    $$f_k=frac{m}{m+k}(f_k+1)+frac{k}{m+k}f_{k-1}$$

    解得

    $$f_k=f_{k-1}+frac{m}{k}$$

    $f_1$的值为$m+1$,则$f_n=1+msum _{i=1}^nfrac{1}{i} $

    最后两个数相乘

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n,m;
    long long inv[2000005]={0,1},ans;
    const long long mod=998244353;
    inline int read(){
        int f=1,w=0;
        char ch=0;
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') w=(w<<1)+(w<<3)+ch-'0',ch=getchar();
        return f*w;
    }
    int main(){
        for(int i=2;i<=2000001;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        n=read(),m=read();+
        for(int i=1;i<=n;i++)(ans+=inv[i])%=mod;
        printf("%lld
    ",(ans*m%mod+1)*(n*inv[m+1]%mod+1)%mod);
        return 0;
    }
    ZS Shuffles Cards
  • 相关阅读:
    (一)版本控制管理器之发展史
    Mysql的binlog日志与mysqlbinlog命令
    centos下mysql中table大小写改为不敏感
    「Flink」RocksDB介绍以及Flink对RocksDB的支持
    redis事务
    零基础转行学习大数据技术需要经过哪些学习步骤?
    SQL Server解惑&mdash;&mdash;对象命名的唯一性小结
    泡泡后台Couchbase缓存使用经验分享
    MySQL_索引原理
    《分布式与云计算》MOOC第三单元课后测试答案
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14310312.html
Copyright © 2011-2022 走看看