当前位置:网站首页>第十四次试验
第十四次试验
2022-07-07 07:09:00 【moyangxian】
#include<iostream>
using namespace std;
const int N=1010;
int g[N][N]={
{
1, 1, 1, 1, 1, 1 },
{
1, 0, 0, 0, 1, 1 },
{
1, 0, 1, 0, 0, 1 },
{
1, 0, 0, 0, 1, 1 },
{
1, 1, 0, 0, 0, 1 },
{
1, 1, 1, 1, 1, 1 }
};
bool vis[N][N];
struct Node{
int x,y;
}ans[N];
int cnt;
int dis[][2]={
0,1,1,0,0,-1,-1,0};
bool check(int x,int y){
if(vis[x][y]||g[x][y]==1) return true;
return false;
}
void dfs(int x,int y,int p){
ans[p]={
x,y};
if(x==4&&y==4){
cout<<"迷宫路径"<<++cnt<<":"<<endl;
for(int i=1;i<=p;i++){
cout<<'('<<ans[i].x<<','<<ans[i].y<<") ";
}
cout<<endl;
return ;
}
for(int i=0;i<4;i++){
int xx=x+dis[i][0];
int yy=y+dis[i][1];
if(check(xx,yy)) continue;
vis[xx][yy]=true;
dfs(xx,yy,p+1);
vis[xx][yy]=false;
}
}
int main(){
cout<<"迷宫对应邻接表"<<endl;
for(int i=0;i<=5;i++){
for(int j=0;j<=5;j++){
cout<<'['<<i<<','<<j<<"]:";
if(i==0||j==0||i==5||j==5){
cout<<endl;
continue;
}
for(int k=0;k<4;k++){
int xx=i+dis[k][0];
int yy=j+dis[k][1];
if(check(xx,yy)) continue;
cout<<'('<<xx<<','<<yy<<')'<<"\t";
}
cout<<endl;
}
}
cout<<"所有迷宫的路径:"<<endl;
vis[1][1]=true;
dfs(1,1,1);
return 0;
}
边栏推荐
- JS judge whether checkbox is selected in the project
- Liunx command
- 【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
- Pick up the premise idea of programming
- 2020浙江省赛
- 信息安全实验二 :使用X-SCANNER扫描工具
- 第一讲:寻找矩阵的极小值
- 剑指 Offer II 107. 矩阵中的距离
- ViewPager2和VIewPager的区别以及ViewPager2实现轮播图
- Addition, deletion, modification and query of ThinkPHP database
猜你喜欢

Information Security Experiment 2: using x-scanner scanning tool

Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion

Detailed explanation of diffusion model

JS逆向教程第一发

In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen

Arthas simple instructions

20排位赛3

沙龙预告|GameFi 领域的瓶颈和解决方案

第一讲:寻找矩阵的极小值
![[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景](/img/fd/5e8f74da25d9c5f7bd69dd1cfdcd61.png)
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
随机推荐
JS inheritance prototype
Unity uses mesh to realize real-time point cloud (I)
Difference between interface iterator and iteratable
Binary tree high frequency question type
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
Using JWT to realize login function
进程和线程的区别
How to solve the problem of golang select mechanism and timeout
Mysql:select ... for update
What development models did you know during the interview? Just read this one
根据热门面试题分析Android事件分发机制(一)
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
flex弹性布局
Over 100000 words_ Ultra detailed SSM integration practice_ Manually implement permission management
印象笔记终于支持默认markdown预览模式
Impression notes finally support the default markdown preview mode
12、 Sort
How to speed up video playback in browser
Dynamics 365Online ApplicationUser创建方式变更