zoukankan      html  css  js  c++  java
  • 无题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
  • 相关阅读:
    GeoMesa Java API-写入与查询数据
    GeoMesa命令行,索引概述
    HBase,以及GeoMesa设计基于HBase的设计分析,从数据模型到典型查询场景,最后进行RowKey设计
    笔趣看小说Python3爬虫抓取
    python网络爬虫
    Kafka客户端Producer与Consumer
    ScalikeJDBC,操作mysql数据,API
    mysqldb
    Python 反射
    Go 类型转换
  • 原文地址:https://www.cnblogs.com/EdSheeran/p/9629260.html
Copyright © 2011-2022 走看看