当前位置:网站首页>[Central South University of forestry science and technology] [Chen] week 7 innovation maze
[Central South University of forestry science and technology] [Chen] week 7 innovation maze
2022-04-21 22:35:00 【Neon Yu Yan】
C2 The innovation is entitled : Maze game . Yes 6*6 Of the lattice , Among them is 8 There's a barrier , You need to get from (1,1) To (6,6), pass with flying colors , Find the minimum number of steps .
010000
000100
001001
100010
011000
000100
// Ouyang Lianzheng // Teacher, I'm watching videos , May be similar to your classmates , But I understand the concept , The video is the breadth maze .
#include<iostream>
#include<queue>
using namespace std;
int a[7][7], v[7][7];// Access array v
struct point
{
int x; int y;
int step;
};
queue<point> r;
int dx[4] = { 0,1,0,-1 };
int dy[4] = {1,0,-1,0};
int main()
{
cout<<" Please enter several rows and columns ";
int n, m,startx,starty,p,q;
cin >> n >> m;
cout<<" Please enter the style of the maze ";
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
cout<<" Please enter the starting and ending positions ";
cin >> startx >> starty >> p >> q;
point start;
start.x = startx;
start.y = starty;
start.step = 0;
r.push(start);// Join the team from the starting point
v[startx][starty] = 1;
int flag = 0;
while (!r.empty())
{
int x = r.front().x, y = r.front().y;
if (x == p && y == q)
{
cout << r.front().step;
break;
}
for (int k = 0; k <= 3; k++)
{
int tx, ty;
tx = x + dx[k];
ty = y + dy[k];
if (a[tx][ty] == 1 && v[tx][ty] == 0)
{
// The team
point temp;
temp.x = tx;
temp.y = ty;
temp.step = r.front().step + 1;
r.push(temp);
v[tx][ty] = 1;
}
}
r.pop();
}
if (flag == 0)
{
cout << " The maze has no exit ";
}
}
版权声明
本文为[Neon Yu Yan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212232153465.html
边栏推荐
猜你喜欢

OpenCV中的Core组件——输入输出XML, YAML(12)

Leetcode146 LRU cache - Simulation - bidirectional linked list - hash table - data structure - operating system

1956年高考数学

「运维有小邓」企业如何解决AD域弱密码问题?

Recursive stack with the help of classical recursive tree

Byte daily practice (OC)

AUTOCAD——三种箭头的画法

2022 intermediate accounting title examination economic law practice questions and answers

字节日常实习(已OC)

CC10000. ZABBIX———————————————
随机推荐
事件分发机制Android,大厂Android面试总结 详细解答
Flow chart of event distribution mechanism, the way for programmers to turn over
L1-055 who is the winner (10 points)
2022 Chongqing's latest architectural eight members (Civil Engineering) simulation question bank and answers
Point cloud bilateral filtering
排序方式(8种)详解6—快速排序
L1-056 猜数字 (20 分)
Reading notes "autumn garden", "driftwood", "my fragrance"
一些网址的收藏
JUNHE shares: the revenue growth in 2021 was steady, and the export performance of benefited products reached a new high
L2-3 sequence traversal of complete binary tree (25 points) -- recursive reduction of binary tree
算法--合并K个升序链表(Kotlin)
2022年中级会计职称考试会计实务练习题及答案
Unlock openharmony technology day! The annual event is about to open!
L1-064 估值一亿的AI核心代码 (20 分)
期货开户在手机上办理安全吗?需要线下办理吗?
第五讲:相关系数
Do you have any good suggestions for brushing questions and how to improve efficiency?
Daily practice questions (3)
行业分析| 互联网医疗的发展