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号湖开始钓起,但是他 ...
随机推荐
- python实现scrapy爬取图片到本地时的sha1摘要算法文件名
2017-03-29 Scrapy爬图片到本地应该会给图片自动生成sha1摘要算法文件名,我第一次用scrapy也不清楚太多,就在程序里自己写了一段实现这一功能的代码.需import hashlib ...
- C#数据之List
一.C# List根据值找到索引值方法 List<int> test = new List<int>(); int index = test .FindIndex(item=& ...
- DirectX 11游戏编程学习笔记之6: 第5章The Rendering Pipeline(渲染管线)
本文由哈利_蜘蛛侠原创,转载请注明出处.有问题欢迎联系2024958085@qq.com 注:我给的电子版是700多页,而实体书是800多页,所以我在提到相关概念的时候 ...
- 超高逼格Log日志打印
代码地址如下:http://www.demodashi.com/demo/12646.html 前言 Log日志的打印一直是一个比较头疼的事,怎样才能让自己的log显示更多信息,怎样才能让自己的log ...
- svn上传代码时出现:Authorization failed
出现该问题基本都是三个配置文件的问题,下面把这个文件列出来 svnserve.conf:[general]anon-access = readauth-access = writepassword-d ...
- Android中database所在文件夹路径(9.6)
1 sd----->data---->对应app---->databases----->创建的db 2 push到pc上,可以使用GUI工具SQLiteSpy直接查看datab ...
- SpringSecurity学习三----------通过Security标签库简单显示视图
© 版权声明:本文为博主原创文章,转载请注明出处 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0& ...
- 【HBase基础教程】1、HBase之单机模式与伪分布式模式安装(转)
在这篇blog中,我们将介绍Hbase的单机模式安装与伪分布式的安装方式,以及通过浏览器查看Hbase的用户界面.搭建hbase伪分布式环境的前提是我们已经搭建好了hadoop完全分布式环境,搭建ha ...
- JavaScript事件使用指南
事件流 事件流描述的是从页面中接收事件的顺序,IE和Netscape提出来差不多完全相反的事件流的概念,IE事件流是事件冒泡流,Netscape事件流是事件捕获流. 事件冒泡 IE的事件流叫做事件冒泡 ...
- Quartz.Net - Lesson 1: 使用Quartz
Lesson 1: 使用Quartz 本系列文章是官方3.x文档的翻译,原文地址:https://www.quartz-scheduler.net/documentation/quartz-3.x/t ...