• 无题1


    题解:

    第一题:

    这道题达到最终状态就停了,p是甲最终赢的概率,我们最后状态即p=1, 或p = 0;最初p = 0.5; 从0.5到1或0的增量都是0.5,甲还要赢x场, 乙还要赢y场,当x,y发生变动时,p改变,假设增量为q, 我们就应该投入 q/0.5 * 2 ^(2n - 1), (占总共钱的比列);

    那么这个q就可以通过上面的式子O(1)得了; 无限递推;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    const ll mod = 1e9 + 7;
    const int M = 1e5 + 10;
    ll v[M << 1],fac[M << 1], vfac[M << 1];
    
    ll ksm(ll a, ll b){
        ll ret = 1;
        for(; b; b >>=1, a=a*a%mod)
            if(b & 1) ret=ret*a%mod;
        return ret;
    }
    ll ni(ll a){
        return ksm (a, mod - 2);
    }
    ll C(int a, int b){
        return fac[a] * vfac[b] % mod * vfac[a - b] % mod;
    }
    
    int main(){
        freopen("beijing.in","r",stdin);
        freopen("beijing.out","w",stdout);
        int n;
        scanf("%d", &n);
        v[1] = 1; fac[0] = vfac[0] = 1;
        for(ll i = 2; i <= 2 * n; i++){//推 i 的逆元
            v[i] = v[mod % i] * (mod - mod/i) % mod;
        }
        for(ll i = 1; i <= 2 * n; i++){
            fac[i] = fac[i - 1] * i % mod;
            vfac[i] = ni(fac[i]);
        }
        ll x = n, y = n;
        ll z = C(x + y - 2, x - 1) * 2 % mod;
        while(x > 0 && y > 0){
            printf("%lld
    ", z);
            z = z * v[x + y - 2] * 2 % mod;
            int opt; scanf("%d", &opt);
            if(!opt) z = z * (--x) % mod;
            else z = z * (--y) % mod;
        }
    } 
    View Code

    第二题:打表找规律,发现就是加一个杨辉三角的*增量

    空间开小了

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define RG register 
    const int M = 2e4 + 10;
    ll a[M], t[M], c[M], fac[M], vfac[M];
    const ll mod = 1e9 + 7;
    inline ll moc(ll a){
        return a >= mod ? a - mod : a;
    }
    int n, m, k; ll q;
    
    ll ksm(ll a, ll b){
        ll ret = 1;
        for(; b; b >>=1, a=a*a%mod)
            if(b & 1) ret=ret*a%mod;
        return ret;
    }
    ll ni(ll a){
        return ksm (a, mod - 2);
    }
    
    void init(){
        fac[0] = vfac[0] = 1;
        for(ll i = 1; i <= 2*(n + 1); i++) fac[i] = fac[i - 1] * i % mod, vfac[i] = ni(fac[i]);
        for(int i = 1; i <= n + 1; i++) c[i] = fac[k - 2 + i] * vfac[k - 1] % mod * vfac[i - 1] % mod;
        
    }
    
    
    
    int main(){
        freopen("hongkong.in","r",stdin);
        freopen("hongkong.out","w",stdout);
        scanf("%d%d%d",&n, &m, &k);
        init();
        //for(int i = 1; i <= n; i++)printf("%lld ", c[i]);    
        int opt, x, y;
        while(m--){
            scanf("%d", &opt);
            if(!opt){
                scanf("%d%d", &x, &y);
                a[x] = moc(a[x] + y);
                for(int i = x; i <= n; i++) t[i] = moc(t[i] + c[i - x + 1] * y % mod);
            }
            else {
                scanf("%d", &x);
                printf("%lld
    ", t[x]);
            }
        }
    } 
    View Code
  • 相关阅读:
    Win32 键盘事件
    好用的Markdown 编辑器及工具
    如何激发您孩子的学习动力和兴趣
    横扫芯片后,紫光欲进军公有云 数百亿资金已到位(大事表)
    C#更改控制台文本颜色
    I/O多路复用
    Python 安装 httpie
    Elasticsearch 5.0
    认证架构
    注册微信小程序
  • 原文地址:https://www.cnblogs.com/EdSheeran/p/9629260.html
Copyright © 2020-2023  润新知