首页 技术 正文
技术 2022年11月20日
0 收藏 744 点赞 4,335 浏览 3310 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,944
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,469
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,283
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,099
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,729
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,766