zoukankan      html  css  js  c++  java
  • BZOJ5091 摘苹果(概率期望)

      大胆猜想每一步都相当于是第一步。稍微验证一下发现是对的。就做完了。

    #include<iostream> 
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define N 100010
    #define P 1000000007
    char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    int read()
    {
        int x=0,f=1;char c=getchar();
        while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
        while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        return x*f;
    }
    int n,m,k,a[N],degree[N],inv,ans;
    int ksm(int a,int k)
    {
        int s=1;
        for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
        return s;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("bzoj5091.in","r",stdin);
        freopen("bzoj5091.out","w",stdout);
        const char LL[]="%I64d
    ";
    #else
        const char LL[]="%lld
    ";
    #endif
        n=read(),m=read(),k=read();
        for (int i=1;i<=n;i++) a[i]=read();
        for (int i=1;i<=m;i++)
        {
            int x=read(),y=read();
            degree[x]++,degree[y]++;
        }
        inv=ksm(2*m,P-2);
        for (int i=1;i<=n;i++) ans=(ans+1ll*a[i]*k%P*degree[i]%P*inv)%P;
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    chartjs 初步
    QT “error: error writing to -: Invalid argument”
    OTL mySQL
    qtcteater pro 文件配置
    Python os.readlink() 方法
    Python os.read() 方法
    Python os.popen() 方法
    Python os.pipe() 方法
    Python os.pathconf() 方法
    ThinkPHP框架前后台的分页调用
  • 原文地址:https://www.cnblogs.com/Gloid/p/10057975.html
Copyright © 2011-2022 走看看