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. 五个常用的Linux监控脚本代码

    bash中 2>&1 & 的解释 1.首先,bash中0,1,2三个数字分别代表STDIN_FILENO.STDOUT_FILENO.STDERR_FILENO,即标准输入(一般 ...

  2. C#字符串操作大全

    ===============================字符串基本操作================================ 一.C#中字符串的建立过程 例如定义变量 strT=&qu ...

  3. CKEditor+SWFUpload实现功能较为强大的编辑器(二)---SWFUpload配置

    在前面配置完CKEditor之后,就可以拥有一个功能挺强大的编辑器了 但是现在还不够,还要能够在发表文字中插入自己电脑上的图片 CKEditor自己好像有这个功能,但是实在是...没法说,很难用(这是 ...

  4. 转:Eclipse常见问题,快捷键收集

    Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1.[ALT+/] Sysout+ System.out.pri ...

  5. [React] Override webpack config for create-react-app without ejection

    The default service worker that comes with create-react-app doesn't allow for very much configuratio ...

  6. 往MySQL数据库datetime类型字段中插入数据库的当前时间

    代码: StringBuilder sb = new StringBuilder(); sb.append(" insert into uosdetailfile ("); sb. ...

  7. 借助backtrace和demangle实现异常类Exception

    C++的异常类是没有栈痕迹的,如果需要获取栈痕迹,需要使用以下函数: #include <execinfo.h> int backtrace(void **buffer, int size ...

  8. react-native 扫一扫功能(二维码扫描)功能开发

    1.安装插件 yarn add react-native-smart-barcode 2.关联 react-native link react-native-smart-barcode 3.修改 an ...

  9. 控制器View是怎样创建的?

    对于非常多程序猿来说控制器和View的关系肯定有点模糊,对于View的创建肯定有一种说不清道不明的感觉.view仅仅是控制器的一个属性.控制器中有很多对view处理的方法.也就是说得控制器管理view ...

  10. 【Excle数据透视】如何隐藏数据透视表字段的分类汇总

    如下图:是显示数据透视表的分类汇总 那么我们现在想弄成以下这样,不显示分类汇总 如何操作呢? 步骤 单击数据透视表任意单元格→数据透视表工具→设计→分类汇总→不显示分类汇总 ***显示分类汇总*** ...