当前位置:网站首页>201604-4 test title: Game (BFS search maze)
201604-4 test title: Game (BFS search maze)
2022-06-25 20:05:00 【Orange cedar】
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;// Don't add using namespace std queu Report errors
struct direct{
int dr,dc;
}direct[4]={
{-1,0},{1,0},{0,-1},{0,1}};
int visited[101][101][300];
struct node{
int row,col,level;
};
int bfs(int n,int m){
// initialization , Queue entry
node start,front,v;
start.row=1;
start.col=1;
start.level=0;
queue<node> q;
q.push(start);
//while loop
while(!q.empty()){
front=q.front();
q.pop();
printf("(%d , %d)---%d\n",front.row,front.col,front.level);
// The boundary conditions
if(front.row==n&&front.col==m)return front.level;
// Search for
for(int i=0;i<4;i++){
v.row=front.row+direct[i].dr;
v.col=front.col+direct[i].dc;
v.level=front.level+1;
// out
if(v.row<1||v.row>n||v.col<1||v.col>m)continue;
// dangerous
if(visited[v.row][v.col][v.level])continue;
// Search forward
visited[v.row][v.col][v.level]=1;
q.push(v);
}
}
return 0;
}
int main(){
int n,m,t,r,c,a,b;
memset(visited,0,sizeof(visited));
scanf("%d%d%d",&n,&m,&t);
for(int i=1;i<=t;i++){
scanf("%d%d%d%d",&r,&c,&a,&b);// Note enter here ,“&” Often make mistakes
for(int j=a;j<=b;j++)visited[r][c][j]=1;
}
int ans=bfs(n,m);
printf("%d",ans);
return 0;
}
边栏推荐
- Redis cache preheating & avalanche & breakdown & penetration
- Randomly generate 100 non repeating numbers between 1 and 150 and put them in the array
- Alicloud centos8.0 installing mysql8
- 206. reverse linked list (insert, iteration and recursion)
- Pcl+vs2019+opencv environment configuration
- II Traits (extractors)
- RPM package installation command
- Case: count the most characters and times
- From now on, I will blog my code
- Vulnhub range - the planes:venus
猜你喜欢

Bloom filter
![[harmonyos] [arkui] how can Hongmeng ETS call pa](/img/19/9d2c68be48417e0aaa0d27068a67ce.jpg)
[harmonyos] [arkui] how can Hongmeng ETS call pa

How to understand var = a = b = C = 9? How to pre parse?

<C>. Branch and loop statements

<C>. Figure guessing game

wooyun-2014-065513

Hdoj topic 2005 day

Automatic fitting when the applet reaches the top

206. reverse linked list (insert, iteration and recursion)

Wechat applet connects to the server to display mqtt data information
随机推荐
Please do not call Page constructor in files
2、 Hikaricp source code analysis of connection acquisition process II
From now on, I will blog my code
wooyun-2014-065513
PAT B1091
Yaml configuration
Applet wx Request encapsulation
Is it safe to open a new bond? Is low commission reliable
PAT B1071
三、HikariCP获取连接流程源码分析三
JS advanced
Huawei in application review test requirements
JS asynchronism (I. asynchronous concept, basic use of web worker)
Jsonp non homologous interaction (click trigger)
Thymleaf template configuration analysis
Uniapp waterfall flow, applet waterfall flow, very simple, suitable for the whole platform
Log in to Huawei game with a minor account, and pop up anti addiction prompt after startup
Teach you how to add custom controls to a map
Redis cache preheating & avalanche & breakdown & penetration
Pdf file download (the download name is the same as the file name)