zoukankan      html  css  js  c++  java
  • 钓鱼(贪心+优先队列+重载运算符)

    钓鱼

    题目描述:
    话说发源于小朋友精心设计的游戏被电脑组的童鞋们藐杀之后非常不爽,为了表示安慰和鼓励,VIP999决定请他吃一次“年年大丰收”,为了表示诚意,他还决定亲自去钓鱼,但是,因为还要准备2013NOIP,z老师只给了他H(1<=H<=16)个小时的空余时间,假设有N(2<=n<=25)个鱼塘都在一条水平路边,从左边到右编号为1、2、3、。。。、n)。VIP是个很讲究效率的孩子,他希望用这些时间钓到尽量多的鱼。他从湖1出发,向右走,有选择的在一些湖边停留一定的时间钓鱼,最后在某一个湖边结束钓鱼。他测出从第I个湖到I+1个湖需要走5*ti分钟的路,还测出在第I个湖边停留,第一个5分钟可以钓到鱼fi,以后再每钓5分钟鱼,鱼量减少di。为了简化问题,他假定没有其他人钓鱼,也不会有其他因素影响他钓到期望数量的鱼。请编程求出能钓最多鱼的数量。
    输入输出格式
    输入格式:
    第一行:湖的数量n。
    第二行:时间h(小时)。
    第三行:n个数,f1,f2,…fn。
    第四行:n个数,d1,d2,….dn。
    第五行:n-1个数,t1,t2,….tn-1
    输出格式:
    一个数,所能钓鱼的最大数量。
    输入输出样例
    输入样例1:
    2
    1
    10 1
    2 5
    2
    输出样例1:
    31

    #include<iostream>
    #include<queue>
    using namespace std;
    const int maxn=30;
    int n,h,ans,tot,t[maxn],d[maxn];
    struct node
    {
        int f;
        int num;
        bool operator < (node x)const
        {
            return f<x.f;
        }
    }a[maxn];
    priority_queue<node> q;
    int main()
    {
        cin>>n>>h;
        h=h*12;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].f;
            a[i].num=i;
        }
        for(int i=1;i<=n;i++)
        cin>>d[i];
        for(int i=1;i<=n-1;i++)
        cin>>t[i];
        for(int i=1;i<=n;i++)
        {
            h=h-t[i-1];tot=0;
            while(!q.empty())
            q.pop();
            for(int j=1;j<=i;j++)
            q.push(a[j]);
            for(int j=h;j>0;j--)
            {
                node s;
                s.f=q.top().f-d[q.top().num];
                s.num=q.top().num;
                if(q.top().f>0)
                tot+=q.top().f;
                q.pop();
                q.push(s);
            }
            ans=max(ans,tot);
        }
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    49. 字母异位词分组
    73. 矩阵置零
    Razor语法问题(foreach里面嵌套if)
    多线程问题
    Get json formatted string from web by sending HttpWebRequest and then deserialize it to get needed data
    How to execute tons of tasks parallelly with TPL method?
    How to sort the dictionary by the value field
    How to customize the console applicaton
    What is the difference for delete/truncate/drop
    How to call C/C++ sytle function from C# solution?
  • 原文地址:https://www.cnblogs.com/cax1165/p/6070998.html
Copyright © 2011-2022 走看看