zoukankan      html  css  js  c++  java
  • HDU 4869 Turn the pokers

    /*
    HDU4869
    http://acm.hdu.edu.cn/showproblem.php?pid=4869
    费马小定理+快速幂 求逆元 暴力组合数
    奇偶性
    */
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    const __int64 Nmax=100005LL;
    const __int64 mod=1000000009LL;
    __int64 fac[Nmax];//i!
    __int64 l,r,n,m;
    void get()
    {
        fac[0]=fac[1]=1LL;
        for(__int64 i=2LL;i<=Nmax-1;i++)
            fac[i]=(fac[i-1]*(i%mod))%mod;
    }
    
    __int64 pow(__int64 base,__int64 n)
    {
        __int64 ans=1LL;
        base=base%mod;
        while(n>0LL)
        {
            if(n&1LL)
                ans=(ans*base)%mod;
            base=(base*base)%mod;
            n>>=1;
        }
        return ans;
    }
    
    __int64 C(__int64 n,__int64 m)
    {
        __int64 ans=1LL;
        ans=fac[n]%mod;
        ans=(ans* (pow(fac[m]*fac[n-m],mod-2)%mod) )%mod;
        // ans=(ans* (pow(fac[m],mod-2)%mod))%mod;
        // ans=(ans* (pow(fac[n-m],mod-2)%mod))%mod;
        return ans;
    }
    
    void get_limit()
    {
        l=r=0LL;
        int x;
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&x);
            __int64 ll,rr;
            //1->0
            if(x<=l)//  x  l  r
                ll=l-x;
            else if(x<=r)// l  x  r  
            {
                if((x&1)==(l&1))
                    ll=0;
                else
                    ll=1;
            }    
            else// l  r  x
                ll=x-r;
    
            //0->1
            if(r+x<=n) 
                rr= r+x;//
                    else if(l+x<=n)
                    {
                        if(((l+x)&1) == (n&1))
                            rr=n;
                        else
                            rr=n-1;
                    }
                    else 
                        rr = 2*n-(l+x);//
                    l=ll,r=rr;
        }
    }
    
    int main()
    {
        //freopen("HDU4869.in","r",stdin);
        get();
        while(scanf("%I64d%I64d",&m,&n)==2)
        {
            get_limit();
            __int64 ans=0LL;
            // printf("%d %d
    ",l,r);
            for(__int64 i=l;i<=r;i+=2)
            {
                ans=(ans+C(n,i)%mod);
                // printf("C(%I64d,%d)=%I64d
    ",n,i,C(n,i));
            }
            ans%=mod;
            while(ans<0)
                ans+=mod;
            printf("%I64d
    ",ans);    
        }
        return 0;
    }
  • 相关阅读:
    [最短路径SPFA] POJ 1847 Tram
    [强连通分量] POJ 1236 Network of Schools
    [强连通分量] POJ 2762 Going from u to v or from v to u?
    [强连通分量] POJ 2186 Popular Cows
    [宽度优先搜索] HDU 1372 Knight Moves
    php错误级别和异常处理
    php配置优化
    魔术方法和魔术常量
    事务
    mysql备份和还原
  • 原文地址:https://www.cnblogs.com/BBBob/p/6522903.html
Copyright © 2011-2022 走看看