当前位置:网站首页>水管工遊戲
水管工遊戲
2022-06-13 01:39:00 【halisi7】
水管工遊戲
問題描述



分析





代碼實現
#include <stdio.h>
int n, m, front,top,flag;
int a[51][51];
int book[51][51];
struct note {
int x;
int y;
};
struct note s[101];
void dfs(int x,int y,int front) {
int i;
if (x == n && y == m + 1) {
flag = 1;
for (i = 0; i < top; i++) {
printf("(%d,%d)", s[i].x, s[i].y);
}
printf("\n---------------------\n");
return;
}
if (x<1 || x>n || y<1 || y>m)
return;
if (a[x][y] == 0)
return;
if (book[x][y] == 1)
return;
s[top].x = x;
s[top].y = y;
top++;
book[x][y] = 1;
//直管
if (a[x][y] >= 5 ) {
if (front == 1) {
dfs(x , y+1, 1);
}
if (front == 2) {
dfs(x+1, y , 2);
}
if (front == 3) {
dfs(x, y - 1, 3);
}
if (front == 4) {
dfs(x - 1, y, 4);
}
}
if (a[x][y] <= 4 && a[x][y] >= 1 ) {
if (front == 1) {
dfs(x+1, y , 2);
dfs(x - 1, y, 4);
}
if (front == 2) {
dfs(x , y+1, 1);
dfs(x , y-1, 3);
}
if (front == 3) {
dfs(x-1, y , 4);
dfs(x + 1, y, 2);
}
if (front == 4) {
dfs(x , y+1, 1);
dfs(x , y-1, 3);
}
}
book[x][y] = 0;
top--;
return;
}
int main() {
int i, j;
scanf_s("%d %d", &n, &m);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
scanf_s("%d", &a[i][j]);
dfs(1, 1, 1);
if (flag == 0) {
printf("找不到路徑。");
}
getchar(); getchar();
return 0;
}
輸入
5 4
5 3 5 3
1 5 3 0
2 3 5 1
6 1 1 5
1 5 5 4
輸出(直接輸出路徑)
(1,1)(1,2)(2,2)(3,2)(3,3)(3,4)(4,4)(5,4)
边栏推荐
- Leetcode question brushing 07 double pointer
- The interviewer only asked me five questions and the interview was over
- Thread code learning notes
- [wsl2]wsl2 migrate virtual disk file ext4 vhdx
- 关于tkinter.Canvas 不显示图片的问题
- Anims of phaser3
- FSOs forest simulation optimization model learning notes
- Temporary objects and compilation optimization
- [leetcode] valid phone number Bash
- 详细受众特征详细解释
猜你喜欢

DFS and BFS notes (II): depth first search (implemented in C language)

V-inline-date, similar to Ctrip, flying pig, time selection with price

服务器安装jupyterlab以及远程登录配置

开发者来稿|AMD赛灵思中文论坛分享 - 提问的智慧

Memory learning book reference
![[leetcode] valid phone number Bash](/img/f8/cecb74f9d8f7c589e62e3a9a874f82.jpg)
[leetcode] valid phone number Bash

Leetcode 05 tree

matplotlib画图中文乱码

关于tkinter.Canvas 不显示图片的问题

How to solve the problems when using TV focusable to package APK in uni app
随机推荐
Differences among bio, NiO and AIO
This of phaser3 add. sprite
Introduction to convolutional neural network
Detailed explanation of Joseph problem
My crawler learning notes
Logical operation bit operation
Answer to matrix theory of Nanjing University of Aeronautics and Astronautics
About tkinter Canvas does not display pictures
FSOs forest simulation optimization model learning notes
Phaser3 load
Reinstall opencv and step on the pit.
numpy多维数组转置transpose
30: Kakfa simulates JSON data generation and transmission
Sliding window summary of TCP connections
服务器安装jupyterlab以及远程登录配置
Record the VMware installation process of VMware Tools and some problems encountered
他山之石:a16z 的 Web3 投资版图
ng-tv-focusable
How many times does the constructor execute?
The storage structure of a tree can adopt the parent representation, that is, the parent pointer array representation. Try to give the corresponding class definition. Each tree node contains two membe