当前位置:网站首页>1.12 learning summary
1.12 learning summary
2022-06-26 04:34:00 【After all, I still walk alone】
Today's main learning content is to see the related concepts of trees and several methods of building trees . Tell the truth , After reading it for a day, I didn't particularly understand . All I know is to use . Linked list and structure to realize one to many operation . It's not like a linear table . So I don't know what to sum up today . But I can still feel , The function of tree is very powerful . So more complex data access . In that case, I will make one today . Let's solve the problem . Also review the contents of the search by the way .
The title is as follows ,
This is a slightly adapted maze problem . He is on a common maze problem , Added a transfer point setting . Originally, the maze problem used DFS and BFS It's quite easy to solve . But on this issue , What the title asks for , Is the quickest way to get there . So I chose BFS To carry out . The general maze problem is to change a variable Store coordinates , And determine whether this coordinate conforms to . Conditions to determine the path . And for the transfer point , I just need to design a function . The value at this coordinate , If it's a transfer point , Let him input this function . And then traverse the entire map . To find another transfer point . The condition is that both values are the same . But the coordinates are different . Then change the value of this variable to the coordinates of another transfer point . Then you can turn this problem into a common maze problem . The rest of the steps are and BFS The template is the same . The specific code is as follows . Of course, my method is still more violent . Because I have to traverse the entire array every time I judge the transfer point . In this case , If there are too many transfer points or the map is large , It is possible that the time limit is exceeded . I think for a long time , I didn't think of any algorithm that could optimize a lot . The specific code is as follows ,
#include<stdio.h>
#include<queue>
#include<stdlib.h>
#include<iostream>
using namespace std;
int n,m; int x1,y4,x3,y3,s;
char map[301][301];
int map1[301][301];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int x2,y2;
struct g{
int x,y,step;
};
queue<g> p;
void l(int &a,int &b){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(map[i][j]==map[a][b] && (i!=a || j!=b))
{a=i,b=j;return;}
}
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
{ cin>>map[i][j];
if(map[i][j]=='@') x1=i,y4=j;
if(map[i][j]=='=') y3=i,x3=j;}
}
p.push(g{x1,y4,0}); map1[x1][y4]=1;
g t1;
int x2,y2;
while(!p.empty()){
t1 = p.front();
if(map[t1.x][t1.y]=='=') {s=t1.step;
break;}
if(map[t1.x][t1.y]>='A' && map[t1.x][t1.y]<='Z'){
l(t1.x,t1.y);
}
for(int i=0;i<4;i++){
x2=t1.x+dx[i]; y2=t1.y+dy[i];
if(x2>=1&&x2<=n&&y2>=1&&y2<=m && map1[x2][y2]!=1 && map[x2][y2]!='#'){
map1[x2][y2] = 1;
p.push(g{x2,y2,t1.step+1});
}
}
p.pop();
}
printf("%d",s);
return 0;
}Today's learning summary , That's it . We must learn more tomorrow .
边栏推荐
- Thinkphp6 using kindeditor
- PHP installation SSH2 extension
- 2020-12-18
- CTF serialization and deserialization
- Zhubo Huangyu: you can try these non-agricultural operation skills
- A troubleshooting of website crash due to high CPU
- Report on demand situation and development trend of China's OTC industry from 2022 to 2028
- Laravel pay payment access process
- Zhubo Huangyu: all the precious metals you want to know are here
- MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
猜你喜欢

MySQL enable logbin in Qunhui docker

Dameng database backup and restore

PHP small factory moves bricks for three years - interview series - my programming life

修改Oracle连接数
![[Qunhui] Internet access + custom port](/img/7d/c00caeade209a48c8f44a4fecb59d5.jpg)
[Qunhui] Internet access + custom port

Computer network high frequency interview questions
![[Qunhui] command line acme SH automatically apply for domain name certificate](/img/7b/8cb99ee0d74692ff6afd8513b02834.jpg)
[Qunhui] command line acme SH automatically apply for domain name certificate

Thinkphp6 using kindeditor

How to use the configured slave data source for the scheduled task configuration class scheduleconfig

A brain map to summarize the needs analysis (a supplement to the actual situation at work)
随机推荐
Guide de la pompe de données Oracle
Be a hard worker from today on
Redis cache message queue
Zhimeng CMS will file a lawsuit against infringing websites
NFT creation and binding of BSC and HT chains
Analysis report on development trend and market demand of global and Chinese molecular diagnostics industry from 2022 to 2028
pip 批量完全卸载包
Database related knowledge
Nightmare
Realize video call and interactive live broadcast in the applet
Redis cluster mode
Laravel uses phpword to generate word documents
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
08_SpingBoot 集成Redis
Physical design of database design (2)
Dameng database backup and restore
Laravel pay payment access process
"Eight hundred"
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Nailing open platform - applet development practice (nailing applet server side)