POJ 1042 Gone Fishing

POJ1328——Radar Installation、POJ1042——Gone Fishing、POJ1456——Supermarket(贪心) 例如,考虑乘积 Prod={a,b,c,d},其中 (pa,da)=(50,2),(pb,db)=(10,1),(pc,dc)=(20,2) 和 (pd,dd)=(30,1)。这是一个典型的区间覆盖问题。可以将问题转化为在不同的终止湖的情况下,如何分配剩余的钓鱼时间,使得钓到的鱼总数最大。一组产品以整数 0 <= n <= 10000 开头,这是集合中的产品数量,然后是 n 对整数 pi di,1 <= pi <= 10000 和 1 <= di <= 10000,指定第 i 个产品的利润和销售截止日期。 阅读详情

Description

John is going on a fishingtrip. He has h hours available (1 <= h <= 16), and there are n lakes inthe area (2 <= n <= 25) all reachable along a single, one-way road. Johnstarts at lake 1, but he can finish at any lake he wants. He can only travelfrom one lake to the next one, but he does not have to stop at any lake unlesshe wishes to. For each i = 1,...,n - 1, the number of 5-minute intervals ittakes 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 tolake 4. To help plan his fishing trip, John has gathered some information aboutthe lakes. For each lake i, the number of fish expected to be caught in theinitial 5 minutes, denoted fi( fi >= 0 ), is known. Each 5 minutes offishing decreases the number of fish expected to be caught in the next 5-minuteinterval by a constant rate of di (di >= 0). If the number of fish expectedto be caught in an interval is less than or equal to di , there will be no morefish left in the lake in the next interval. To simplify the planning, Johnassumes that no one else will be fishing at the lakes to affect the number offish he expects to catch.
Write a program to help John plan his fishing trip to maximize the number offish expected to be caught. The number of minutes spent at each lake must be amultiple of 5.

Input

You will be given a number ofcases in the input. Each case starts with a line containing n. This is followedby 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, aline of n - 1 integers ti (1 <=i <=n - 1). Input is terminated by a casein which n = 0.

Output

For each test case, print thenumber of minutes spent at each lake, separated by commas, for the planachieving the maximum number of fish expected to be caught (you should printthe entire plan on one line even if it exceeds 80 characters). This is followedby a line containing the number of fish expected.
If multiple plans exist, choose the one that spends as long as possible at lake1, even if no fish are expected to be caught in some intervals. If there isstill a tie, choose the one that spends as long as possible at lake 2, and soon. 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

 

t题目简介:有n个湖,给h个小时。每次从第一个湖开始。在每个湖的钓鱼速度为fi条/5分钟,每隔5分钟速度变化一次,变为fi = (fi-di)。从i到i+1需要ti*5分钟。问最多能钓多少条鱼。在每个湖钓鱼的时间为多少。

方法:贪心+枚举。每次算出到到最远的湖i后剩下的时间。以i之前湖中最大的钓鱼速度开始。不断变化,一保持最大的速度。

#include<stdio.h>
#include<string.h>

int main()
{
	int lakes, times, max, num, temp;
	int fi[30], di[30], ti[30];
	int time[30][30], sum[30];//time[a][b]表示最远达到a湖的过程中,b湖停留的次数
	while(scanf("%d",&lakes),lakes)
	{

		memset(di,0,sizeof(di));
		memset(time,0,sizeof(time));
		memset(sum,0,sizeof(sum));

		//input
		scanf("%d",×);
		
		for(int i = 0;i<lakes;i++)
		{
			scanf("%d",&fi[i]);
		}

		for(int i = 0;i<lakes;i++)
		{
			scanf("%d",&di[i]);
		}

		for(int i = 0;i<lakes - 1;i++)
		{
			scanf("%d",&ti[i]);
		}


		//solve
		for(int i = 0;i<lakes;i++)
		{
			int total = times * 12;

			//算出能够达到的最远的湖后剩下的时间
			for(int j = 0;j<i;j++)
			{
				total -= ti[j];
			}

			for(int j = 0;j<total;j++)
			{
				int a, b;
				a = fi[0];
				b = time[i][0] * di[0];
				max = a - b;

				if(max < 0)
				{
					max = 0;
				}

				num = 0;
				//找到此时最大的fi
				for(int k = 0; k<=i; k++)
				{
					temp = fi[k]-time[i][k]*di[k];
					if(temp < 0)
					{
						temp = 0;
					}
					if(max < temp)
					{
						max  = temp;
						num = k;
					}
				}

				time[i][num]++;
				sum[i] += max;
			}
		}
	
		max = 0;
		for(int i = 1; i<lakes; i++)
		{	
			if(sum[max]<sum[i])
			{
				max = i;
			}
		}

		for(int i = 0; i<lakes - 1;i++)
		{	
			printf("%d, ",time[max][i]*5);	
		}
		printf("%d\n",time[max][lakes - 1]*5);

		printf("Number of fish expected: %d\n\n",sum[max]);
	}
	return 0;
}


 

 

 

 

 

poj1042Gone Fishing 贪心 Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 34616   Accepted: 10727 Description John is going on a fishing trip. He has h hours available (1 阅读详情

相关推荐

[软考]系统架构设计师 备考经验分享(一) - 备考计划篇

前言 上周末刚刚结束了软考架构师的考试,自我感觉考的还可以,大概率是过了。 两次参加软考,一次中级嵌入式,一次高级架构师,都是备考不到两个月时间,尤其是架构师这次考试内容和本职工作有不小的差别,并且需要同时备考三个科目,在高强度地备考中感觉是摸索出到了一点软考的技巧与经验。 打算趁还记得,赶紧写几篇文章做下梳理总结,算是给将来自己考系分、高项或者其他考试做个记录,也希望能够帮到正在备考的大家。 先把第一步,个人的备考计划分享给大家。 自身情况分析 首先,请大家一定先明确三个问题,这三个问题会直接影响到你的

_ 6408

1859: Gone Fishing

Description     John is going on a fishing trip. He has h hours available ( 1 <= h <= 16 ), and there are n lakes in the area (2 <= n <= 25), L1 , ..., Ln, all reachable along a single, one-w

w571523631的博客 404

SMPTE ST 2110 概论(一)

SMPTE ST 2110 概论(一)前言ST 2110与ST 2022-6ST 2110-10:基本结构与时序ST 2110-20:未压缩的视频流后续 前言 这是一份我在实习期间制作的,关于SMPTE ST 2110的简单介绍。 这篇文章主要以梳理总结 SMPTE ST 2110 的概念为主,关于具体的内容,比如IP数据报的格式、RTP时间戳的具体代码内容等等,大家可以查阅 SMPTE ST 2...

Cidd0422的博客 2万+

POJ 1042 Gone Fishing(钓鱼问题)__贪心

DescriptionJohn is going on a fishing 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,

不若乘风来 1017

如何用capl操控程控电源(RS232)

capl脚本操控RS232

xiaohuanxiong_的博客 3996

k8s配置habor作为镜像地址之后,如果harbor中没有镜像,如何设置自动从阿里云官方镜像仓库下载

通过 Harbor 的远端仓库可以集中管理。如果你在上游设置了 image prefix 为 library,那么对外访问 harbor.your-domain.com/library/nginx:latest 就会被 Harbor 去上游拉取 registry.cn-hangzhou.aliyuncs.com/library/nginx:latest 并缓存。- 将集群中的镜像地址改为 Harbor 的域名,比如 harbor.your-domain.com/library/nginx:latest。

极客栈 433

POJ 1042

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 7092   A

ericxieforever的专栏 1509

第076篇:大涡模拟进阶

大涡模拟(Large Eddy Simulation, LES)是介于直接数值模拟(DNS)和雷诺平均方法(RANS)之间的重要湍流模拟方法。本文深入介绍动态Smagorinsky模型、尺度相似模型、WALE模型和隐式LES等高级亚格子模型。通过Python实现槽道湍流和圆柱绕流的LES求解器,详细展示近壁面处理、动态系数计算和亚格子应力建模技术。大涡模拟,亚格子模型,动态模型,Smagorinsky,WALE模型,尺度相似模型,近壁面处理,槽道湍流LES的核心思想是对Navier-Stokes方程进行空间

2401_87715305的博客 743

NYOJ 30Gone Fishing(贪心)

Gone Fishing 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachable

大神养成中..... 6145

Python爬虫实战:社交媒体热点事件追踪与情感分析可视化

本文探讨了如何利用Python爬虫技术从微博和Twitter等社交媒体平台抓取数据,进行热点事件追踪和情感分析,并通过可视化方式展示舆论情感变化。文章详细介绍了最新的爬虫技术、数据处理方法和可视化实现,提供了完整的代码示例,帮助读者构建自己的社交媒体分析系统。关键词:Python爬虫、社交媒体分析、情感分析、数据可视化、热点追踪爬虫框架:Requests-HTML、aiohttp、Twint(Twitter专用)数据处理文本处理:Jieba(中文分词)、NLTK(英文处理)情感分析。

2201_76125261的博客 1105

2024年11月架构设计师案例分析真题回顾,附参考答案、解析及所涉知识点(一)

软考高级系统架构设计师考试包含三个科目:信息系统综合知识、案例分析和系统架构设计论文。考试形式为机考。本文主要回顾2024年下半年(2024-11-10)系统架构设计师考试上午第二科案例分析的题目,同时附带参考解答、解析和所涉知识点。

一几文的编程学习笔记。 2423

Fishing

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=75513#problem/F 题意:R and C (1  《=R;C 《= 100), 的矩阵,上面有个数,代表打鱼的话的收益,也代表放鱼的话的失去的收益,然后现在规定:放两次鱼,打一次鱼,每次放鱼,都要求本次放鱼的ij均大于上次放鱼的ij,捕鱼也是这样,但是捕鱼和放鱼之间没有

ruclion的专栏 349

NVIDIA Isaac GR00T N1 入门教程(一) 人形机器人多模态大语言模型

英伟达™ Isaac GR00T N1 是世界上首个用于通用仿人机器人推理和技能的开放式基础模型。该跨体模型采用多模态输入(包括语言和图像)在不同环境中执行操作任务。GR00T N1 在一个庞大的仿人机器人数据集上进行训练,该数据集包括真实捕获数据、使用英伟达 Isaac GR00T Blueprint 组件生成的合成数据(神经生成轨迹示例)以及互联网规模的视频数据。通过后期训练,它可以适应特定的应用、任务和环境。

2506_90492529的博客 3055

POJ-1042 Gone Fishing (贪心法求最佳钓鱼方案

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

今天天气不错 3191

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

poj 1042 Gone Fishing

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 26066   Accepted: 7674 Description John is going on a fishing trip. He has h hours available (1 <=

WEYuLi的专栏 809

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ1042 Gone Fishing

题目来源:http://poj.org/problem?id=1042 题目大意:   John有h个小时的时间想去钓鱼。(1<=h<=16).有n个池塘(2<=n<=25),它们的分布沿着一条单行的小路。John从第一个池塘处出发,他可以沿着小路向前走,在想停下来的池塘处钓鱼,对于路径的终点没有限制。为了钓到最多的鱼,John对各个池塘做了调查。若给路径上的池塘依次编...

weixin_30702413的博客 452

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj 1042 Gone Fishing(贪心)

Description John is going on a fishing 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 lak

ZAQ的博客 593

poj 1042Gone Fishing

//Memory 256kB Time 0ms 代码长度:1955B  #include #include #include #include #include using namespace std; int n,h; struct lake{ int f; int d; }; int t[27]; lake l[27]; lake ll[27]; int tt[27]; int be

baby的专栏 685

POJ-1042:Gone Fishing

时间限制:  2000ms  内存限制:  65536kB 描述 John is going on a fishing 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-w

精灵的博客 1967

poj1042 Gone Fishing

Description John is going on a fishing trip. He has h hours available (1 &lt;= h &lt;= 16), and there are n lakes in the area (2 &lt;= n &lt;= 25) all reachable along a single, one-way ...

JSK670072474的博客 266
下一篇: POJ 1195 Mobile phones
涅槃phy
博客等级 码龄14年 22粉丝 87原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值