当前位置:网站首页>第十四次试验
第十四次试验
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;
}
边栏推荐
- thinkphp3.2信息泄露
- Redis common commands
- Unity shader (basic concept)
- 第一讲:包含min函数的栈
- 【无标题】
- Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
- 2020浙江省赛
- ComputeShader
- Unity uses mesh to realize real-time point cloud (II)
- 章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
猜你喜欢
随机推荐
How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
Sqlplus garbled code problem, find the solution
JS逆向教程第一发
Unity uses mesh to realize real-time point cloud (II)
Information Security Experiment 3: the use of PGP email encryption software
请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
Redis common commands
Unity uses mesh to realize real-time point cloud (I)
小程序滑动、点击切换简洁UI
HCIP 第一天 笔记整理
在EXCEL写VBA连接ORACLE并查询数据库中的内容
The configuration and options of save actions are explained in detail, and you won't be confused after reading it
Netease cloud wechat applet
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
Create an int type array with a length of 6. The values of the array elements are required to be between 1-30 and are assigned randomly. At the same time, the values of the required elements are diffe
C# XML的应用
Information Security Experiment 2: using x-scanner scanning tool
第一讲:鸡蛋的硬度
NETCORE 3.1 solves cross domain problems
Dynamics 365Online ApplicationUser创建方式变更