• POJ1042 Gone Fishing



    采用贪心策略。

    假设他从1湖泊走到x 湖泊,这还剩下 h*12 - sigma(T1--Tx-1)。(单位时间为5分钟)。然后再用剩下的时间去钓1-x的湖泊的鱼。 每次都选择最多鱼的湖泊钓。


    code:

    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    using namespace std;
    const int maxn = 30;
    
    int f[maxn], tf[maxn], d[maxn], t[maxn], path[maxn];
    int ans, p[maxn];
    
    int main()
    {
        int  h, n, i, j, k;
        while(scanf("%d",&n),n) {
            scanf("%d",&h);
            h *= 12;
            for(i=1; i<=n; ++i) scanf("%d",&f[i]);
            for(i=1; i<=n; ++i) scanf("%d",&d[i]);
            for(i=1; i<=n-1; i++) scanf("%d",&t[i+1]);
            for(i=2,t[1]=0; i<=n; ++i) t[i] += t[i-1];
            ans = -1000;
            for(k=1; k<=n; ++k)
                if(h>t[k]) {
                    int th = h - t[k];
                    int sum = 0;
                    memset(path, 0, sizeof path );
                    for(i=1; i<=n; ++i) tf[i] = f[i];
                    while(th>0) {
                        int maxx  = 0;
                        int mark = 0;
                        for(i=1; i<=k; ++i)
                            if(maxx<tf[i]) {
                                maxx = tf[i];
                                mark  = i;
                            }
                        if(!mark) break;
                        sum += maxx;
                        tf[mark] -= d[mark];
                        path[mark]++;
                        th--;
                    }
                    path[1] += th;
                    if(ans<sum) {
                        ans = sum;
                        for(j=1; j<=n; j++)
                            p[j] = path[j];
                    }
                }
            for(i=1; i<n; ++i) printf("%d, ",p[i]*5);
            printf("%d
    ",p[i]*5);
            printf("Number of fish expected: %d
    
    ", ans);
        }
        return 0;
    }
    


  • 相关阅读:
    MFC Slider控件 去掉边上的虚线
    VC學習網址
    全局程序集缓存工具 (Gacutil.exe)
    滚动条集合
    调用 DialogBox 会失败解决方法
    全局程序集缓存GAC”是什么概念
    UltraVNC:超实用的远程控制工具(图)
    VC程序员之无法选择的命运
    C++类
    角色权限批量设置,随点!
  • 原文地址:https://www.cnblogs.com/pangblog/p/3329024.html
Copyright © 2020-2023  润新知