当前位置:网站首页>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 .
边栏推荐
- Resolve PHP is not an internal or external command
- Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr
- The select option in laravel admin contains a large amount of data
- What should I do if I don't understand the precious metal indicators
- OSS CDN alicloud configuration method
- Dameng database backup and restore
- 35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling
- BSC 及HT 等链的NFT 创造及绑定图片教程
- 6、 Project practice --- identifying cats and dogs
- digital image processing
猜你喜欢
Clickhouse stand alone installation
一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)
35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling
Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
六、项目实战---识别猫和狗
Understand CGI and fastcgi
Nailing open platform - applet development practice (nailing applet server side)
Install dbeaver and connect Clickhouse
Tp6 controller does not exist: app\index\controller\index
随机推荐
SQL related knowledge - constraints
numpy 通用函数
C generic
mysql自帶的性能測試工具mysqlslap執行壓力測試
08_ Spingboot integrated redis
排序查询
List of provinces, cities and counties in China
The select option in laravel admin contains a large amount of data
Syntax error of go language generic in IDE
Introduction to markdown grammar
Microsoft prohibits Russian users from downloading and installing win10/11
08_SpingBoot 集成Redis
Thymeleaf data echo, single selection backfill, drop-down backfill, time frame backfill
Jenkins introduces custom jars
SSH password free login, my server password free login to the other server, the other server password free login to your server
SQL related knowledge - DQL
SixTool-多功能多合一代挂助手源码
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
Etcd watch principle
PHP syntax summary