Gone Fishing 贪心暴力模拟

Gone Fishing
时间限制:3000 ms | 内存限制:65535 KB
难度:5

描述
John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i = 1,…,n - 1, the number of 5-minute intervals it takes to travel from lake i to lake i + 1 is denoted ti (0 < ti <=192). For example, t3 = 4 means that it takes 20 minutes to travel from lake 3 to lake 4. To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi( fi >= 0 ), is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di (di >= 0). If the number of fish expected to be caught in an interval is less than or equal to di , there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch.
Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.

输入
    You will be given a number of cases in the input. Each case starts with a line containing n. This is followed by a line containing h. Next, there is a line of n integers specifying fi (1 <= i <=n), then a line of n integers di (1 <=i <=n), and finally, a line of n - 1 integers ti (1 <=i <=n - 1). Input is terminated by a case in which n = 0. 
输出
    For each test case, print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught (you should print the entire plan on one line even if it exceeds 80 characters). This is followed by a line containing the number of fish expected. 
    If multiple plans exist, choose the one that spends as long as possible at lake 1, even if no fish are expected to be caught in some intervals. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on. Insert a blank line between cases. 
样例输入

    2 
    1 
    10 1 
    2 5 
    2 
    4 
    4 
    10 15 20 17 
    0 3 4 3 
    1 2 3 
    4 
    4 
    10 15 50 30 
    0 3 4 3 
    1 2 3 
    0 

样例输出

    45, 5 
    Number of fish expected: 31 

    240, 0, 0, 0 
    Number of fish expected: 480 

    115, 10, 50, 35 
    Number of fish expected: 724 

题意 在一条水平的路边有n个湖可以钓鱼,编号一次为1.2.3…n,John有h个小时的时间用于钓鱼,他希望用这些时间钓到尽量多的鱼,他从第一个湖出发,有选择的在一些湖边停留一定的时间钓鱼,最后在某个湖边停止钓鱼,为了制定好的钓鱼计划,John测出了从第 i 个湖走到第 i+1 个湖需要的时间为 5*ti 分钟,还测出了在第 i 个湖边初始的钓鱼数目 fi 和每钓一次 下一次钓上来的次数就减少 di ,求出钓鱼最多的方案,若存在多个最优方案,求出在第一个湖钓鱼时间最长的,若还有多个,则输出在第二个钓鱼最长的方案。。

贪心+暴力模拟+惨绝人寰格式题。。。。
枚举钓鱼的终点,就能向前分析出方案,枚举储存 然后寻找最优解。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include <vector>
#include<string>
#include<string.h>
#include<functional>
#include<queue>
#include<cmath>
using namespace std;
class pool
{
public:
    int fishes,ranks,zhejiu;
    bool operator < (const pool a) const
    {
        if(fishes==a.fishes)
            return ranks>a.ranks;
        return fishes<a.fishes;
    }
};
class plan
{
public:
    int fishes_times[30];
    int maxs;
    plan(int a[],int maxs):maxs(maxs)
    {
        memcpy(fishes_times,a,sizeof fishes_times);
    }
};
bool cmp(plan a,plan b)
{
    if(a.maxs==b.maxs)
        return a.fishes_times[0]>b.fishes_times[0];
    return a.maxs>b.maxs;
}
int cost[30];
pool pools[30];
vector<plan> V;
void fish(int n,int hour)
{
    hour-=(cost[n]*5);
    int ftimes[30]={0};
    priority_queue<pool> Q;
    for(int j=0;j<=n;j++)
        Q.push(pools[j]);
    //printf("%d:%dmins\n",n,hour);
    int times=hour/5;
    int the_maxs=0;
    while(times--)
    {
        pool now=Q.top();
        Q.pop();
        if(now.fishes==0)
        {
            times++;
            break;
        }
        the_maxs+=now.fishes;
        now.fishes-=now.zhejiu;
        if(now.fishes<0)
            now.fishes=0;
        ftimes[now.ranks]++;
        Q.push(now);
    }
    if(times>0)
        ftimes[0]+=times;
    V.push_back(plan(ftimes,the_maxs));
}
int main()
{
    int n,hour;
    while(~scanf("%d",&n)&&n)
    {scanf("%d",&hour);
    V.clear();
    memset(pools,0,sizeof pools);
    memset(cost,0,sizeof cost);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&pools[i].fishes);
        pools[i].ranks=i;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&pools[i].zhejiu);
    }
    for(int i=1;i<n;i++)
    {
        scanf("%d",&cost[i]);
        cost[i]+=cost[i-1];
    }
    hour*=60;
    for(int i=0;i<n;i++)
    {
        if(hour-(cost[i]*5)<0)
            break;
        fish(i,hour);
    }
    sort(V.begin(),V.end(),cmp);
    for(int i=0;i<n;i++)
    {
        if(i)
            printf(", %d",V[0].fishes_times[i]*5);
        else
            printf("%d",V[0].fishes_times[i]*5);


    } puts("");
    printf("Number of fish expected: %d\n\n",V[0].maxs);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值