【强连通分量】Instantaneous Transference

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点阐述了AI音视频处理的应用场景和实现方法,如语义识别、物体检测、语音变声等。通过实例分析,揭示了这些技术如何提升游戏体验和互动性。
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 N, M (2 ≤ N, M ≤ 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,M - 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

先强连通分量缩点,然后SPFA之。

注意数组清零的问题。

Accode:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>

const int maxR = 50;
const int maxN = 2010;
const int SIZE = 0xffff;

struct vec
{
    int x, y;
    vec() {}
    vec(int x, int y): x(x), y(y) {}
};
struct Edge {int v; Edge *next;};

Edge *edge[maxN];
char mp[maxR][maxR];
bool marked[maxR][maxR], visit[maxN];
int belong[maxR][maxR];
int DFN[maxR][maxR], Low[maxR][maxR];
int ord[maxR][maxR], cnt[maxN];
int dist[maxN], q[SIZE + 1];
vec to[maxN], stack[maxN];
int t, n, m, K, top, Index, Bcnt, ans, f, r;

void tarjan(int x, int y)
{
    if (mp[x][y] == '#') return;
    DFN[x][y] = Low[x][y] = ++Index;
    stack[++top] = vec(x, y);
    marked[x][y] = 1;
    if (y < m - 1 && mp[x][y + 1] != '#')
    {
        int u = x, v = y + 1;
        if (!DFN[u][v])
        {
            tarjan(u, v);
            if (Low[u][v] < Low[x][y])
                Low[x][y] = Low[u][v];
        }
        else if (marked[u][v] && DFN[u][v] < Low[x][y])
	//开始在这里打错一个变量,
	//把marked[u][v]打成了marked[x][y],调了很久。
            Low[x][y] = DFN[u][v];
    }
    if (x < n - 1 && mp[x + 1][y] != '#')
    {
        int u = x + 1, v = y;
        if (!DFN[u][v])
        {
            tarjan(u, v);
            if (Low[u][v] < Low[x][y])
                Low[x][y] = Low[u][v];
        }
        else if (marked[u][v] && DFN[u][v] < Low[x][y])
            Low[x][y] = DFN[u][v];
    }
    if (mp[x][y] == '*')
    {
        int u = to[ord[x][y]].x, v = to[ord[x][y]].y;
        if (mp[u][v] != '#') //注意要有边才能枚举。
        {
            if (!DFN[u][v])
            {
                tarjan(u, v);
                if (Low[u][v] < Low[x][y])
                    Low[x][y] = Low[u][v];
            }
            else if (marked[u][v] &&
                     DFN[u][v] < Low[x][y])
                Low[x][y] = DFN[u][v];
        }
    }
    if (DFN[x][y] == Low[x][y])
    {
        ++Bcnt;
        vec tmp;
        do
        {
            tmp = stack[top--];
            marked[tmp.x][tmp.y] = 0;
            belong[tmp.x][tmp.y] = Bcnt;
            if (isdigit(mp[tmp.x][tmp.y]))
                cnt[Bcnt] += mp[tmp.x][tmp.y] - '0';
        } while (tmp.x != x || tmp.y != y);
    }
    return;
}

inline void init()
{
    memset(marked, 0, sizeof marked);
    memset(visit, 0, sizeof visit);
    memset(belong, 0, sizeof belong);
    memset(cnt, 0, sizeof cnt);
    memset(DFN, 0, sizeof DFN);
    memset(edge, 0, sizeof edge);
    K = n = m = top = Index = Bcnt = ans = f = r = 0;
    return;
}

inline int Spfa()
{
    memset(dist, ~0x3f, sizeof dist);
    int ans = cnt[belong[0][0]];
    dist[belong[0][0]] = ans;
    visit[belong[0][0]] = 1;
    q[r++] = belong[0][0];
    f &= SIZE;
    while (f != r)
    {
        int u = q[f++];
        f &= SIZE;
        visit[u] = 0;
        for (Edge *p = edge[u]; p; p = p -> next)
        if (dist[u] + cnt[p -> v] > dist[p -> v])
        {
            int v = p -> v;
            if ((dist[v] = dist[u] + cnt[v]) > ans)
                ans = dist[v];
            if (!visit[v])
            {
                visit[v] = 1;
                q[r++] = v;
                r &= SIZE;
            }                
        }
    }
    return ans;
}

inline void insert(int u, int v)
{
    if (u == v) return;
    for (Edge *p = edge[u]; p; p = p -> next)
        if (p -> v == v) return;
	//注意重新建图时的判重,以减少枚举量。
    Edge *p = new Edge;
    p -> v = v;
    p -> next = edge[u];
    edge[u] = p;
    return;
}

int main()
{
    freopen("Instantaneous_Transference.in", "r", stdin);
    freopen("Instantaneous_Transference.out", "w", stdout);
    scanf("%d", &t);
    for (; t; --t)
    {
        init();
        scanf("%d%d\n", &n, &m);
        for (int i = 0; i < n; ++i)
        {
            gets(mp[i]);
            for (int j = 0; j < m; ++j)
            if (mp[i][j] == '*')
                ord[i][j] = K++;
        }
        for (int i = 0; i < K; ++i)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            to[i] = vec(x, y);
        }
        tarjan(0, 0);
        for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
        {
            if (j < m - 1 && mp[i][j + 1] != '#')
                insert(belong[i][j], belong[i][j + 1]);
            if (i < n - 1 && mp[i + 1][j] != '#')
                insert(belong[i][j], belong[i + 1][j]);
            if (mp[i][j] == '*' &&
                mp[to[ord[i][j]].x][to[ord[i][j]].y] != '#')
                insert(belong[i][j],
                       belong[to[ord[i][j]].x][to[ord[i][j]].y]);
		//注意实际无边的情况。
        }
        printf("%d\n", Spfa());
    }
    return 0;
}

基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值