• LightOJ 1030 Discovering Gold


    期望,$dp$。

    设$ans[i]$为$i$为起点,到终点$n$获得的期望金币值。$ans[i]=(ans[i+1]+ans[i+2]+ans[i+3]+ans[i+4]+ans[i+5]+ans[i+6])/6+a[i]$,不到$6$个的单独处理一下。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
    }
    
    int a[120],T,n;
    double ans[120];
    
    int main()
    {
        scanf("%d",&T); int cas=1;
        while(T--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                ans[i]=1.0*a[i];
            }
            for(int i=n-1;i>=1;i--)
            {
                int cnt=0; double sum=0;
                for(int j=1;j<=6;j++)
                {
                    if(i+j>n) break;
                    cnt++; sum=sum+ans[i+j];
                }
                ans[i]=ans[i]+sum/cnt;
            }
            printf("Case %d: %lf
    ",cas++,ans[1]);
        }
        return 0;
    }
  • 相关阅读:
    python-Lock进程同步解决互斥
    python-Event事件处理进程同步
    python-queue队列通信
    python-无名管道进程通信
    python-signal
    python-购物车
    python-多进程类封装
    python-哈夫曼树
    python-双向链表
    openstack 开发step-by-step
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6289415.html
Copyright © 2020-2023  润新知