Gone Fishing

John is going on a fising 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.

Input

  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.

Output

  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.

Sample Input

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

Sample Output

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个池塘,每个池塘钓鱼有个可以钓到的期望值,钓5分钟会减少期望值,可以且只能去下一个相邻池塘,并且不能回来,去下一个池塘会耗费一定的时间

问,如何决策可以钓最多鱼。并且要输出在每一个池塘钓的鱼的数量,格式也挺麻烦的

//一道贪心的题目,但是一直误差错误。。。我觉得应该没错了

就是先算出如果最后在每一个池塘结束钓鱼的话,可以钓到的最大的鱼的数量。用一个数组保存,然后,再遍历找到最大值输出就行了,

 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int f_i[];//初始期望值
int temp_i[];//等于上面的
int d_i[];//期望递减值
int t_i[];//跨池塘耗费时间
int n,h; int spend[][];//在每一个池塘待的时间,spend[][0]是存在这个池塘钓鱼的期望值
int Diao(int k)
{
memset(spend[k],,sizeof(spend[k]));
int i,res=,time=h*;
for (i=;i<=k;i++)
temp_i[i]=f_i[i];
for (i=;i<k;i++)//路上的耗费都去掉
time-=t_i[i]*;
while (time>)
{
int max_=-,max_p;
for (i=;i<=k;i++)//每次找到最大的
{
if (temp_i[i]>max_)
{
max_=temp_i[i];
max_p=i;
}
}
if (max_>)//还可以钓鱼
{
res+=max_;
temp_i[max_p]-=d_i[max_p];
spend[k][max_p]+=;
time-=;
}
else
{
spend[k][]+=time;
break;
}
}
spend[k][]=res;//0位置放期望值
return ;
} int main()
{
while (scanf("%d",&n)&&n)
{
scanf("%d",&h);
int i;
for (i=;i<=n;i++)
scanf("%d",&f_i[i]);
for (i=;i<=n;i++)
scanf("%d",&d_i[i]);
for (i=;i<n;i++)
scanf("%d",&t_i[i]);
for (i=;i<=n;i++)//在每一个池塘结束可钓最大值
Diao(i);
int ans=,pos;
for (i=;i<=n;i++)
{
if (spend[i][]>ans)
{
ans=spend[i][];
pos=i;
}
else if (spend[i][]==ans)//等于,就要比谁在前面的池塘待的久
{
for (int j=;j<=n;j++)
{
if (spend[i][j]>spend[pos][j])
{
pos=i;
break;
}
else if (spend[i][j]<spend[pos][j])
break;
}
}
}
for (i=;i<n;i++)
printf("%d, ",spend[pos][i]);
printf("%d\n",spend[pos][i]);
printf("Number of fish expected: %d\n\n",ans); }
return ;
}

Gone Fishing(贪心)的更多相关文章

  1. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

  2. POJ 1042 Gone Fishing#贪心

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...

  3. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  4. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  5. HDU 6709“Fishing Master”(贪心+优先级队列)

    传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...

  6. 【Fishing Master HDU - 6709 】【贪心】

    题意分析 题意:题目给出n条鱼,以及捕一条鱼所用的时间k,并给出煮每一条鱼的时间,问抓完并煮完所有鱼的最短时间. 附题目链接 思路: 1.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这 ...

  7. Fishing Master (思维+贪心)

    题目网站:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Problem Description Heard that eom is a fishing ...

  8. [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...

  9. poj -- 1042 Gone Fishing(枚举+贪心)

    题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...

随机推荐

  1. 在vs2012中配置使用iisexpress

    在vs2012中配置使用iisexpress   vs2012支持基于iisexpress的web站点调试,这样可以尽可能与生产环境具备一样的环境. 但是,如果在vs2012中直接配置iis目录,通常 ...

  2. 在elasticsearch里如何高效的使用filter

    今天在做查询category的时候,遇到一个问题,查询出来的cateogry为food,fun的形式.但是我需要的只是food或者fun 不包含逗号. 开始想着在aggs后再做过滤,这样有些麻烦.遂在 ...

  3. oracle数据库中函数和存储过程中的区别

    一.函数必须有返回值,过程没有返回值: 二.函数可以单独执行,过程必须通过execute执行: 三.函数可以嵌入SQL中执行,过程不能. 可以将比较复杂的查询写成函数,然后在过程中调用.

  4. (一)Thymeleaf用法——Thymeleaf简介

    1. thymeleaf认识 参考官方文档(Project version: 3.0.5.RELEASE)   1.1 介绍 Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎,能 ...

  5. 后期给项目加入Git版本控制

    一.为项目加上Git 1.进入对应文件夹 2.git init(初始化一个空的代码仓库) 3.git add .(将当前目录和子目录的文件标记为要添加到代码仓库) 4.git commit -m &q ...

  6. Ubuntu 12.04 的IP 设置

      通过访问 /etc/network/interfaces 实现动态IP 或者静态IP 的设置. vim /et/network/interfaces 1.设置动态IP auto lo iface ...

  7. php代码中使用换行及(\n或\r\n和br)的应用

    浏览器识别不了\n或\r\n,这两个换行符是文本换行符,文本文件有效;假设须要将结果输出到浏览器或打印到显示器,代码中使用br;假设仅仅是在源码中换行.则使用\n或\r\n,感兴趣的朋友能够了解下,也 ...

  8. linux内核参数分析

    这是原来在51cto写的,现在都转到博客园来了 1.time_wait连接数过多,需要调整内核参数 http://blog.renhao.org/2010/07/setup-linux-kernel- ...

  9. OrCAD16.6中对比两份DSN文件的方法

    OrCAD16.6中对比两份改版前后DSN文件的方法 两种方法: (1)第一种用软件对比netlist (2)用orcad自带的对比功能 一.将两份要对比的原理图都生成orTelesis.dll格式的 ...

  10. Android:Activity+Fragment及它们之间的数据交换(一)

    简单介绍: 为什么要用Fragment?使用Fragment能够在一个Activity中实现不同的界面. Fragment与Fragment之间的动画切换,远比Activity与Activity之间的 ...