HDU1242 Rescue BFS+优先队列

本文介绍了一个经典的迷宫问题解决方案,利用BFS算法和优先队列找到从起点到终点的最短路径,同时考虑了路和卫兵的不同花费时间。

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               
Problem Description
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.

Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach Angel" is to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or her?) to move into the grid. We assume that we moving up, down, right, left takes us 1 unit time, and killing a guard takes 1 unit time, too. And we are strong enough to kill all the guards.

You have to calculate the minimal time to approach Angel. (We can move only UP, DOWN, LEFT and RIGHT, to the neighbor grid within bound, of course.)
 

Input
First line contains two integers stand for N and M.

Then N lines follows, every line has M characters. "." stands for road, "a" stands for Angel, and "r" stands for each of Angel's friend.  

Process to the end of the file.
 

Output
For each test case, your program should output a single integer, standing for the minimal time needed. If such a number does no exist, you should output a line containing "Poor ANGEL has to stay in the prison all his life."  
 

Sample Input

  
7 8#.#####.#.a#..r.#..#x.....#..#.##...##...#..............
 

Sample Output

  
13
 


 

题意:X代表卫兵,a代表终点,r代表起始点,.代表路,#代表墙

路花费一秒,x花费两秒

问到达终点的最少时间

思路:BFS+优先队列的果题

 

#include <stdio.h>#include <string.h>#include <queue>using namespace std;struct node{    int x,y,step;    friend bool operator<(node n1,node n2)    {        return n2.step<n1.step;    }};int n,m,vis[205][205];char map[205][205];int x1,x2,y1,y2;int to[4][2] = {1,0,-1,0,0,1,0,-1};int check(int x,int y){    if(x<0 || y<0 || x>=n || y>=m || !vis[x][y] || map[x][y] == '#')        return 1;    return 0;}int bfs(){    int i;    priority_queue<node> Q;    node a,next;    a.x = x1;    a.y = y1;    a.step = 0;    Q.push(a);    vis[x1][y1] = 0;    while(!Q.empty())    {        a = Q.top();        Q.pop();        if(a.x == x2 && a.y == y2)            return a.step;        for(i = 0; i<4; i++)        {            next = a;            next.x+=to[i][0];            next.y+=to[i][1];            if(check(next.x,next.y))//判断                continue;            next.step++;            if(map[next.x][next.y] == 'x')//卫兵处多花费了一秒                next.step++;            if(vis[next.x][next.y]>=next.step)//存入最小时间            {                vis[next.x][next.y] = next.step;                Q.push(next);            }        }    }    return 0;}int main(){    int i,j;    while(~scanf("%d%d",&n,&m))    {        for(i = 0; i<n; i++)        {            scanf("%s",map[i]);            for(j = 0; map[i][j]; j++)            {                if(map[i][j] == 'r')                {                    x1 = i;                    y1 = j;                }                else if(map[i][j] == 'a')                {                    x2 = i;                    y2 = j;                }            }        }        memset(vis,1,sizeof(vis));        int ans = 0;        ans = bfs();        if(ans)            printf("%d\n",ans);        else            printf("Poor ANGEL has to stay in the prison all his life.\n");    }    return 0;}


 

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
内容概要:本文围绕直驱式永磁同步电机(PMSM)的矢量控制策略开展系统性研究,基于Simulink平台构建了完整的闭环仿真模型,深入探讨了电机在矢量控制下的动态响应特性与控制性能。研究内容涵盖了矢量控制的核心理论与关键技术模块,包括Clarke与Park坐标变换、转子磁场定向控制(FOC)、SVPWM调制算法、双闭环PI控制器(电流环与速度环)的设计与参数整定。通过仿真验证了系统在启动、突加负载及变速工况下的稳定性、抗干扰能力与动态调节精度,有效实现了对电机转矩与转速的精确控制。该模型不仅有助于深化对PMSM控制机理的理解,也为高性能电机驱动系统的算法开发与工程化应用提供了可靠的仿真验证平台。; 适合人群:具备自动控制原理、电机学基础及Simulink仿真能力的电气工程、自动化、新能源等相关专业的高年级本科生、研究生以及从事电机驱动开发的初级科研人员与工程师。; 使用场景及目标:①作为高校课程设计、毕业设计或科研项目中PMSM控制系统的学习案例,用于掌握矢量控制算法的实现流程与模块化设计方法;②帮助研究人员理解各控制环节间的耦合关系,通过调整PI参数优化系统性能,并为进一步研究无传感器控制、弱磁扩速、先进非线性控制策略等高级课题奠定基础; 阅读建议:建议结合经典电机控制教材同步学习,重点剖析各功能模块的信号流向与数学原理,亲自动手搭建仿真模型,通过改变运行条件和控制器参数观察系统响应变化,从而深入掌握矢量控制系统的动态特性和调试技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值