Gone Fishing(贪心)
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(贪心)的更多相关文章
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
- POJ 1042 Gone Fishing#贪心
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- HDU 6709“Fishing Master”(贪心+优先级队列)
传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...
- 【Fishing Master HDU - 6709 】【贪心】
题意分析 题意:题目给出n条鱼,以及捕一条鱼所用的时间k,并给出煮每一条鱼的时间,问抓完并煮完所有鱼的最短时间. 附题目链接 思路: 1.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这 ...
- Fishing Master (思维+贪心)
题目网站:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Problem Description Heard that eom is a fishing ...
- [贪心,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 ...
- poj -- 1042 Gone Fishing(枚举+贪心)
题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...
随机推荐
- BindVertexbuffer
stride 的意思是 inputstream.layout 的大小 比如 description是 pos uv normal stride 就是一组pos uv normal的大小 ns 里面 ...
- Bean的作用域scope
Bean的作用域scope 1.singleton 单例,指一个bean容器中只存在一份 2.prototype 每次请求(每次使用)创建新的实例,destroy方式不生效 3.request 每次h ...
- Solr6.6.0 用 SimplePostTool索引文件
一.背景介绍 Solr启动并运行之后,并不包含任何数据,在solr的安装目录下的bin目录中,有一个post工具,我们可以使用这个工具往solr上传数据,这个工具必须在命令行中执行,post工具是一个 ...
- [iOS 高级] iOS远程推送与本地推送大致流程
本地推送: UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { ...
- 【PA2012】【BZOJ4289】Tax
Description 给出一个N个点M条边的无向图,经过一个点的代价是进入和离开这个点的两条边的边权的较大值.求从起点1到点N的最小代价. 起点的代价是离开起点的边的边权.终点的代价是进入终点的边的 ...
- zookeeper启动错误 ---- Unable to load database on disk
zk启动报错 解决办法,进入zkdata目录删除version-2下面的所有文件 参考: https://issues.apache.org/jira/browse/ZOOKEEPER-1546 [h ...
- selenium执行报错:Process refused to die after 10 seconds, and couldn't taskkill it
十二月 02, 2015 5:16:56 下午 org.openqa.selenium.os.ProcessUtils killWinProcess 警告: Process refused to di ...
- jdk/java版本与Android源码编译中的错误
错误一:javap未指向有效的java版本 Traceback (most recent call last): File "../../base/android/jni_generator ...
- 倍福TwinCAT(贝福Beckhoff)基础教程5.1 TwinCAT-3 读写注册表
读写注册表和读写文件一样,里面涉及的输入类型比较复杂,需要参考官方范例 sSubKey是指注册表的路径 sValName是指注册表要写入的名值对的名称 eValType是一个枚举类型(而且不是什么常规 ...
- MPTCP 源码分析(一) MPTCP的三次握手
简述: MPTCP依然按照正常的TCP进行三次握手,只是在握手过程中增加了MPTCP特有的信息. 建立过程 三次握手过程如下图所示: 左边客户端发送的第一个SYN包携带有客户端 ...