当前位置:网站首页>Plumber game
Plumber game
2022-06-13 01:39:00 【halisi7】
Plumber game
Problem description



analysis





Code implementation
#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;
// Straight pipe
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(" No path found .");
}
getchar(); getchar();
return 0;
}
Input
5 4
5 3 5 3
1 5 3 0
2 3 5 1
6 1 1 5
1 5 5 4
Output ( Direct output path )
(1,1)(1,2)(2,2)(3,2)(3,3)(3,4)(4,4)(5,4)
边栏推荐
猜你喜欢
随机推荐
Idea installation tutorial
Study notes on the introduction paper of face recognition deep facial expression recognition: a survey
Super complete regular expressions
Note: common gadgets in project architecture
Three paradigms of database
Work and life
Record the VMware installation process of VMware Tools and some problems encountered
Crypto JS reports uglifyjs error
Explanation and application of prefix sum (one-dimensional, two-dimensional)
About retrieving ignored files in cornerstone
MySQL performance optimization
redis
Anims of phaser3
五、库存查询功能的完善
[wsl2]wsl2 migrate virtual disk file ext4 vhdx
This of phaser3 add. sprite
csdn涨薪技术之Jmeter接口测试数据库断言的实现与设计
matplotlib画图中文乱码
Leetcode question 20
六、出库管理功能的实现









