zoukankan      html  css  js  c++  java
  • Eating Everything Efficiently

    问题 E: Eating Everything Efficiently

    时间限制: 1 Sec  内存限制: 128 MB  Special Judge
    提交: 60  解决: 5
    [提交] [状态] [命题人:admin]

    题目描述

    Margriet A. is in pizza heaven! She has bought a one-day access pass to Pizza World. Pizza World is a food festival, where all stands have their own special type of pizza. Margriet would really like to try many different types of pizza, but she thinks that she can only eat two pizzas in total. Therefore, she has come up with a cunning plan: at each stall she visits she decides whether she wants to buy this pizza or not. At the first stall where she decides to make a purchase, she will buy and eat exactly one pizza.
    At the second one, she will buy and eat half a pizza, and at the third she will eat one quarter of a pizza, etc.. Therefore, at the kth stall where she decides to buy some pizza, she will eat  part of a pizza. This way she makes sure that she will never get full!
    In order to ensure that the flow of people in the park is adequate, the pizza stalls are connected by one-way paths, and to make sure that everyone will leave the festival, it is made impossible to visit a pizza stall more than once. However, every stall can be reached from the stall at the entrance, which is the stall with number 0. 
    Of course, Margriet has her own taste: she will like some pizzas more than others. Eating pizza from a stall will give her a certain amount of satisfaction which is equal to Margriet’s personal stall satisfaction number multiplied by the fraction of a whole pizza she eats there.
    Her total satisfaction is the sum of satisfactions of every stall she visits. Can you help Margriet plot a route between the pizza stalls that satisfies her the most?

    输入

    • Two integers 1 ≤ n ≤ 5 · 105 and 0 ≤ m ≤ 5 · 105, the number of pizza stalls and the number of one way connections.
    • The second line has n integers c0, . . . , cn−1, 0 ≤ ci ≤ 109, the amount of enjoyment Margriet gets from eating one pizza at stall i.
    • The next m lines each contain 2 integers 0 ≤ s < n and 0 ≤ t < n, ndicating a one way path from stall s to stall t. No connection will appear twice in the input.

    输出

    Print the maximal amount of enjoyment Margriet can reach at the pizza fair. Your answer will be considered correct if it differs from the actual answer by at most 10−6 absolutely or relatively.

    样例输入

    5 5
    1 4 6 2 100
    0 1
    1 2
    0 3
    2 4
    3 4
    

    样例输出

    100
    #pragma GCC optimize(3,"Ofast","inline")
    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 5e5 + 10;
    const int N=28;
    struct node{
        int to,nx;
    }o[maxn];
    int n,m;
    int head[maxn],val[maxn],tot,vis[maxn];
    double pre[N+1],dp[maxn][N+1];
    inline void add_edge(int u,int v){
        o[++tot].to=v;
        o[tot].nx=head[u];
        head[u]=tot;
    }
    inline void solve(int cur){
        if(vis[cur])return;
        vis[cur]=1;
        dp[cur][0]=0,dp[cur][1]=val[cur];
        for(register int i=head[cur];i;i=o[i].nx){
            int to=o[i].to;
            solve(to);
            for(register int j=1;j<27;++j){
                if(dp[to][j-1]!=-1){
                    dp[cur][j]=max(dp[cur][j],dp[to][j-1]+val[cur]*pre[j-1]);
                }
                if(dp[to][j]!=-1){
                    dp[cur][j]=max(dp[cur][j],dp[to][j]);
                }
            }
        }
    }
    int main() {
        //freopen("1.txt","r",stdin);
        pre[0]=1;
        for(register int i=1;i<N;++i){
            pre[i]=pre[i-1]/2.0;
            //printf("pre[%d] = %.10f
    ",i,pre[i]);
        }
        scanf("%d%d",&n,&m);
        for(register int i=0;i<=n;++i){
            for(register int j=0;j<=28;++j){
                dp[i][j]=1;
            }
        }
        for(register int i=1;i<=n;++i)scanf("%d",&val[i]);
        for(register int i=1,u,v;i<=m;++i){
            scanf("%d%d",&u,&v);
            ++u,++v;
            add_edge(v,u);
        }
        for(register int i=1;i<=n;++i){
            if(!vis[i])solve(i);
        }
        double res=0;
        for(register int i=1;i<=n;++i){
            for(register int j=0;j<27;++j){
                res=max(res,dp[i][j]);
            }
        }
        printf("%.10f
    ",res);
        return 0;
    }
     
  • 相关阅读:
    从上往下打印二叉树
    栈的压入、弹出序列
    连续子数组的最大和
    链表中环形的入口
    1月项目痛点
    problem:vue组件局部刷新,在组件销毁(destroyed)时取消刷新无效问题
    重点:浏览器的工作原理
    12月中旬项目中出现的几个bug解决方法的思考
    12月中项目问题复盘之对项目进度把控的反思
    problem: vue之数组元素中的数组类型值数据改变却无法在子组件视图更新问题
  • 原文地址:https://www.cnblogs.com/czy-power/p/11420595.html
Copyright © 2011-2022 走看看