贪心算法之钓鱼

博客探讨了贪心算法在解决钓鱼问题中的应用。通过枚举在每个湖泊结束钓鱼,选择剩余鱼最多的位置,若多个湖泊相同则选择编号最小的,以此优化策略。
摘要由CSDN通过智能技术生成

枚举在第i个湖结束钓鱼,那么花在路上的时间确定。贪心策略是每次在鱼剩余最多的地方钓鱼,如果有多个湖,则取编号最小的

出列,更新再入列

#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <memory>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <queue>
using namespace std;
struct node
{
    int f,d,id,t;
    friend bool operator <(const node &a,const node &b)
    {
        if(a.f==b.f)
            return a.id > b.id;
        else
            return a.f < b.f;
    }
};
node fish[30];
priority_queue <node> q;
int n,T;
int Time[30];
int best[30];
int main()
{
    cin >> n;
    while(n!=0)
    {
        cin >> T;
        T*=12;
        for(int i=0; i<n; i++)
        {
            cin >> fish[i].f;
            fish[i].id = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值