【POJ 3592】 Instantaneous Transference(强连通缩点+最长路)

本文解析了一道名为InstantaneousTransference的算法题,通过强连通缩点和最长路径的方法解决迷宫中的采矿问题。游戏场景由一个矩形区域组成,包含不同数量的矿石及传送门,目标是最大化收集矿石的数量。

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

【POJ 3592】 Instantaneous Transference(强连通缩点+最长路)

Instantaneous Transference
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 6265 Accepted: 1411

Description

It was long ago when we played the game Red Alert. There is a magic function for the game objects which is called instantaneous transfer. When an object uses this magic function, it will be transferred to the specified point immediately, regardless of how far it is.

Now there is a mining area, and you are driving an ore-miner truck. Your mission is to take the maximum ores in the field.

The ore area is a rectangle region which is composed by n × m small squares, some of the squares have numbers of ores, while some do not. The ores can't be regenerated after taken.

The starting position of the ore-miner truck is the northwest corner of the field. It must move to the eastern or southern adjacent square, while it can not move to the northern or western adjacent square. And some squares have magic power that can instantaneously transfer the truck to a certain square specified. However, as the captain of the ore-miner truck, you can decide whether to use this magic power or to stay still. One magic power square will never lose its magic power; you can use the magic power whenever you get there.

Input

The first line of the input is an integer T which indicates the number of test cases.

For each of the test case, the first will be two integers NM (2 ≤ NM ≤ 40).

The next N lines will describe the map of the mine field. Each of the N lines will be a string that contains M characters. Each character will be an integer X (0 ≤ X ≤ 9) or a '*' or a '#'. The integer X indicates that square has X units of ores, which your truck could get them all. The '*' indicates this square has a magic power which can transfer truck within an instant. The '#' indicates this square is full of rock and the truck can't move on this square. You can assume that the starting position of the truck will never be a '#' square.

As the map indicates, there are K '*' on the map. Then there follows K lines after the map. The next K lines describe the specified target coordinates for the squares with '*', in the order from north to south then west to east. (the original point is the northwest corner, the coordinate is formatted as north-south, west-east, all from 0 to N - 1,- 1).

Output

For each test case output the maximum units of ores you can take.  

Sample Input

1
2 2
11
1*
0 0

Sample Output

3

Source


题目大意是给出一个n*m的图,从0,0出发 问怎样得到最高分

图中有三种点 0~9表示达到当前点可得分值 ‘*’为传送门 ‘#’为墙(不可达)

要求只能向右或者向下走

走到*时 可以选择传送 也可以不传送 *格子可以无数次传送

之后k行表示从上到下 从左到右每个*传送到的坐标x y


这是题目大意 如果没有*格子 就是一个裸的最长路 或者dp

由于存在*格子 因此可能有环 这样就没法直接bfs

因此先用邻接表存图 然后对于每个点跑Tarjan并把每个环都缩为一点

然后重新建图 新图中所有的环都变成了一个单点 就可以放心bfs了


代码量略大......

<span style="font-size:14px;">#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout)

using namespace std;
const int INF = 0x3f3f3f3f;
const int msz = 10000;
const double eps = 1e-8;

struct Edge
{
	int v,next;
};

//原本的权值
int val[2333];
//缩点后的权值
int nval[2333];
//第一次建图
int head[2333];
Edge eg[23333];
//第二次建图
int nhead[2333];
Edge neg[23333];
int tp;

//缩点后对应的新编号
int pos[2333];
//遍历时序
int dfn[2333],low[2333];
int vis[2333];
int dis[2333];
char mp[44][44];
int mx,tm,n,m,nid;
stack <int> s;

void Add(int u,int v)
{
	eg[tp].v = v;
	eg[tp].next = head[u];
	head[u] = tp++;
}

void Tarjan(int u)
{
	s.push(u);
	vis[u] = 1;
	dfn[u] = low[u] = tm++;
	int v;

	for(int i = head[u]; i != -1; i = eg[i].next)
	{
		v = eg[i].v;
		if(vis[v] == 0)
		{
			Tarjan(v);
			low[u] = min(low[u],low[v]);
		}
		else if(vis[v] == 1) low[u] = min(low[u],dfn[v]);
	}

	if(dfn[u] == low[u])
	{
		while(s.top() != u)
		{
			v = s.top();
			s.pop();
			pos[v] = nid;
<span style="white-space:pre">			</span>//把环中所有点的权值都加到缩成的点上
			nval[nid] += val[v];
			vis[v] = -1;
		}
		v = s.top();
		s.pop();
		pos[v] = nid;
		nval[nid] += val[v];
		vis[v] = -1;
		++nid;
	}
}

void init()
{
	memset(head,-1,sizeof(head));
	memset(val,0,sizeof(val));
	memset(nval,0,sizeof(nval));
	memset(vis,0,sizeof(vis));
	nid = tp = mx = tm = 0;
}

void spfa(int u)
{
	queue <int> q;
	q.push(u);

	memset(vis,0,sizeof(vis));
	memset(dis,0,sizeof(dis));
	vis[u] = 1;
	dis[u] = nval[u];
	mx = dis[u];
	int v;

	while(!q.empty())
	{
		u = q.front();
		q.pop();
		vis[u] = 0;

		for(int i = nhead[u]; i != -1; i = neg[i].next)
		{
			v = neg[i].v;
			if(dis[v] < dis[u]+nval[v])
			{
				dis[v] = dis[u]+nval[v];
				mx = max(mx,dis[v]);
				if(!vis[v])
				{
					q.push(v);
					vis[v] = 1;
				}
			}
		}
	}
}

int main()
{
	//fread();
	//fwrite();

	int t,x,y;
	scanf("%d",&t);

	while(t--)
	{
		init();
		scanf("%d%d",&n,&m);

		for(int i = 0; i < n; ++i)
		{
			scanf("%s",mp[i]);
		}

		for(int i = 0; i < n; ++i)
			for(int j = 0; j < m; ++j)
			{
				if(mp[i][j] == '#') continue;

				if(mp[i][j] == '*')
				{
					scanf("%d%d",&x,&y);
					if(mp[x][y] != '#');
					Add(i*m+j,x*m+y);
				}
				else val[i*m+j] = mp[i][j]-'0';

				if(i > 0 && mp[i-1][j] != '#') Add((i-1)*m+j,i*m+j);
				if(j > 0 && mp[i][j-1] != '#') Add(i*m+j-1,i*m+j);
			}
				
		for(int i = 0; i < n*m; ++i)
			if(!vis[i]) Tarjan(i);

		tp = 0;
		memset(nhead,-1,sizeof(nhead));

		for(int i = 0; i < n*m; ++i)
		{
			for(int j = head[i]; j != -1; j = eg[j].next)
			{
				if(pos[i] == pos[eg[j].v]) continue;
				neg[tp].v = pos[eg[j].v];
				neg[tp].next = nhead[pos[i]];
				nhead[pos[i]] = tp++;
			}
		}

		spfa(pos[0]);

		printf("%d\n",mx);
	}

	return 0;
}
</span>


### HRTF算法原理及应用 #### HRTF的基本原理 HRTF(Head Related Transfer Function,头部相关传递函数)是一种用于模拟三维空间声音定位的数字信号处理技术。其核心思想是通过数学模型来描述声音从声源传播到双耳过程中所受到的物理影响,包括头部、耳廓、耳道等结构对声波的反射、折射和衍射效应。 在实际环境中,当一个声音到达人的耳朵时,由于人体结构的影响,不同方向的声音会具有不同的频谱特征。大脑利用这些特征以及时间差和强度差来判断声音的方向。HRTF通过测量或计算特定方向下的这些特征,并将其表示为一对滤波器(分别对应左右耳),从而使得经过HRTF处理的声音能够在立体声耳机上重现原始的空间位置感[^1]。 #### HRTF的数据获取 为了构建准确的HRTF数据集,通常需要进行精确的测量实验。实验中使用人工头模型或者真人受试者,在自由场条件下放置多个扬声器于不同的方位角和仰角,然后记录每个位置处由扬声器发出的测试信号经过人头与耳朵后的响应。随后,将采集到的数据转换成频率域的形式,形成对应的HRTF滤波器组。这种个性化定制的数据能够提供更加真实的听觉体验,但同时也增加了获取成本[^1]。 #### HRTF的应用领域 - **虚拟现实(VR)与增强现实(AR)**:在VR/AR系统中,HRTF被用来创建沉浸式的音频环境,让用户即使闭着眼睛也能感知到周围世界的存在及其变化。 - **游戏开发**:特别是在射击类游戏中,玩家可以通过脚步声、枪击声等音效快速识别敌人的具体方位,提高游戏的真实性和互动性[^2]。 - **远程会议系统**:借助HRTF技术可以实现更自然的多方通话体验,让参与者更容易分辨说话者的身份。 - **助听设备**:对于某些类型的助听器而言,采用适当的HRTF策略可以帮助佩戴者更好地理解来自各个方向的声音信息。 #### HRTF面临的挑战 尽管HRTF提供了强大的空间音频解决方案,但在实际应用过程中仍然存在一些难题: - 个性化问题:每个人的身体构造都有所差异,因此通用型HRTF可能无法达到最佳效果; - 计算复杂度高:实时应用时需要大量的运算资源来执行卷积操作; - 动态跟踪:如果用户头部移动,则必须相应调整应用的HRTF以保持正确的空间感知。 针对上述问题的研究正在不断推进之中,比如通过机器学习方法预测个性化的HRTF参数、优化算法减少计算负担等手段来改善用户体验。 ```python import numpy as np from scipy.signal import convolve def apply_hrtf(audio_signal, hrtf_left, hrtf_right): """ Apply HRTF filters to mono audio signal to create binaural output. :param audio_signal: Mono input signal (numpy array) :param hrtf_left: Left ear HRTF filter coefficients (numpy array) :param hrtf_right: Right ear HRTF filter coefficients (numpy array) :return: Binaural output (numpy array with shape [length, 2]) """ left_channel = convolve(audio_signal, hrtf_left, mode='full') right_channel = convolve(audio_signal, hrtf_right, mode='full') return np.column_stack((left_channel, right_channel)) ``` 该代码示例展示了如何将给定方向的HRTF应用于单声道音频信号以生成双声道输出。这里使用了`scipy.signal.convolve`函数来进行卷积运算,这是实现HRTF效果的关键步骤之一。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值