POJ 1042 Gone Fishing

本文探讨了深度学习技术在音视频处理、音视频直播、图像处理AR特效等领域的应用,包括图像色彩空间、视频编解码算法、音频编解码算法、视频容器、FFmpeg音视频编解码、硬件编解码、音频处理滤波等方面的应用实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}


 

 

 

 

 

一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
### 北京大学POJ 1042问题代码实现 北京大学POJ平台的1042问题是关于字符串匹配的问题,通常可以通过使用KMP算法来高效解决。以下是针对该问题的详细分析和代码实现。 #### 问题描述 给定一个模式串(pattern)和一个文本串(text),需要判断模式串是否为文本串的子串。如果存在,则输出模式串首次出现的位置;否则输出-1。 #### KMP算法原理 KMP算法的核心思想是利用已匹配部分的信息避免不必要的回溯,从而提高效率[^1]。通过构建部分匹配表(Failure Function),可以快速跳过不必要比较的部分。 #### 代码实现 以下是一个基于Python的KMP算法实现: ```python def compute_lps(pattern): lps = [0] * len(pattern) length = 0 # 长度 of the previous longest prefix suffix i = 1 while i < len(pattern): if pattern[i] == pattern[length]: length += 1 lps[i] = length i += 1 else: if length != 0: length = lps[length - 1] else: lps[i] = 0 i += 1 return lps def kmp_search(text, pattern): m = len(pattern) n = len(text) lps = compute_lps(pattern) i = 0 # index for text[] j = 0 # index for pattern[] while i < n: if pattern[j] == text[i]: i += 1 j += 1 if j == m: return i - j # 返回匹配位置 elif i < n and pattern[j] != text[i]: if j != 0: j = lps[j - 1] else: i += 1 return -1 # 如果未找到匹配 # 示例输入 text = "ABC ABCDAB ABCDABCDABDE" pattern = "ABCDABD" # 调用函数 result = kmp_search(text, pattern) print(result) # 输出结果 ``` 上述代码中,`compute_lps`函数用于生成部分匹配表,而`kmp_search`函数则实现了KMP算法的核心逻辑[^2]。 #### 算法复杂度 KMP算法的时间复杂度为O(n + m),其中n是文本串长度,m是模式串长度。这使得它在处理大规模数据时非常高效[^3]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值