zoukankan      html  css  js  c++  java
  • HDU6656 Kejin Player

    题意

    一个人初始在1级,从i级升级到i+1级需要ai的费用,有pi的概率升级成功,(1-pi)的概率升级失败降到xi级。共有n(5e5)级,q(5e5)询问,每组询问查询从L级升到R级花费的期望。
    题目连接

    思路

    这个题关键是期望是可以相减的,也就是说,E(L,R)=E(1,R)-E(1,L)。我们需要dp预处理得到每个E(1,i)记为dp[i],dp[i+1]=dp[i]+a[i]+(1-p[i])*(dp[i+1]-dp[x[i]])。移项化简一下就行了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int mo = 1000000000+7;
    const int maxn = 500000+10;
    
    inline LL read(){
        LL f=1,x=0;
        char s=getchar();
        while(s<'0' || s>'9'){
            if(s=='-')
                f=-1;
            s=getchar();
        }
        while(s>='0' && s<='9'){
            x=x*10+s-'0';
            s=getchar();
        }
        return x*f;
    }
    
    int n,q;
    LL r[maxn],s[maxn],x[maxn],a[maxn];
    LL dp[maxn];
    
    LL power(LL x,int y)
    {
        LL ans=1;
        while (y)
        {
            if (y&1) ans=ans*x%mo;
            x=x*x%mo;
            y>>=1;
        }
        return ans;
    }
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            n=read(); q=read();
            for (int i=1;i<=n;i++) r[i]=read(),s[i]=read(),x[i]=read(),a[i]=read();
            dp[1]=0;
            for (int i=1;i<=n;i++) dp[i+1]=(  dp[x[i]]+( ((s[i]*power(r[i],mo-2))%mo)*((dp[i]+a[i]-dp[x[i]]+mo)%mo) )%mo  )%mo;
            for (int i=1;i<=q;i++)
            {
                int l=read(),r=read();
                LL ans=(dp[r]-dp[l]+mo)%mo;
                printf("%lld
    ",ans);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    数组的操作
    数据类型的判断
    插入排序法
    数组
    文件路径
    POJ 1149 PIGS(最大流)
    POJ 2186 Popular Cows(强联通+缩点)
    POJ 1463 Strategic game(二分图最大匹配)
    POJ 2761 Feed the dogs(平衡树or划分树or主席树)
    POJ 2528 Mayor's posters(线段树)
  • 原文地址:https://www.cnblogs.com/zhanggengchen/p/11436431.html
Copyright © 2011-2022 走看看