作业帮 > 综合 > 作业

acm编程问题;题意:S到T的最短路径,但是行走过程中改变方向的话步数要加1,输出最小步数,不能到达输出-1;测试数据:

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 09:05:54
acm编程问题;
题意:S到T的最短路径,但是行走过程中改变方向的话步数要加1,输出最小步数,不能到达输出-1;
测试数据:
Sample Input
2
5 5
#####
#...#
#.#.#
#S#T#
#####
4 5
#.#.#
#.#.#
#S#T#
#####
Sample Output
8
-1
以下是我的代码:
#include
#include
#include
#include
#include
using namespace std;
struct node{
int x,y;
int step;
char fx;
};
char map[110][110];
int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int num[120];
int n,m;
int sx,sy,dx,dy;
bool flag;
node f;
int k1;
int bfs()
{
int i,j,k;
int tx,ty;
char temp;
int sstep;
queueq;
node front,rear;
while(!q.empty())q.pop();
q.push(f);
while(!q.empty())
{
front=q.front();
q.pop();
if(front.x==dx&&front.y==dy){
num[k1++]=front.step;
flag=1;
}
map[front.x][front.y]='#';
for(i=0;i
测试数据可以通过……有什么不对吗