当前位置:网站首页>Jeux de plombiers
Jeux de plombiers
2022-06-13 01:39:00 【Halisi 7】
Jeux de plombiers
Description du problème



Analyse





Mise en œuvre du Code
#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;
//Tube droit
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("Impossible de trouver le chemin.");
}
getchar(); getchar();
return 0;
}
Entrée
5 4
5 3 5 3
1 5 3 0
2 3 5 1
6 1 1 5
1 5 5 4
Produits( Chemin de sortie direct )
(1,1)(1,2)(2,2)(3,2)(3,3)(3,4)(4,4)(5,4)
边栏推荐
- Network communication tcp/ip
- 项目实训(十七)---个人工作总结
- Use koa to mock data and set cross domain issues
- Alexnet implements image classification of caltech101 dataset (pytorch Implementation)
- Create a simple game interface using pyGame
- 兴趣相似的受众群体
- How to solve the problems when using TV focusable to package APK in uni app
- Memory learning book reference
- Facial expression recognition dataset
- Sonarqube local installation
猜你喜欢

Set and array conversion, list, array

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

MySQL download and installation

How does Apple add QQ email?

Tweets movement description and chart display
![[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx](/img/e9/4e08e07c2de2f99c2938e79f7f1c44.png)
[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx

Quickly set the computer to turn off automatically

Leetcode question brushing 04 string

Large end storage and small end storage

V-inline-date, similar to Ctrip, flying pig, time selection with price
随机推荐
MySQL related summary
Note: common gadgets in project architecture
This of phaser3 add. sprite
Project training (XVII) -- personal work summary
【斯坦福計網CS144項目】Lab1: StreamReassembler
Leetcode question 20
About retrieving ignored files in cornerstone
Summary of various installation methods of Lab View
谷歌的智能出价有几种?
MySQL performance optimization
一种不带CPU的DPU架构:Hyperion
pytorch : srcIndex < srcSelectDimSize
V-inline-date, similar to Ctrip, flying pig, time selection with price
详细受众特征详细解释
Should the audience choose observation mode or positioning mode?
Explanation and application of prefix sum (one-dimensional, two-dimensional)
[WSL2]限制WSL2可访问的硬件资源(CPU/内存)
Simple operation of MySQL database
Leetcode question brushing 07 double pointer
Memory learning book reference