![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
03搜索图论
张学恒
这个作者很懒,什么都没留下…
展开
-
破纪录者(Google Kickstart2020 Round D Problem A)
对于每个测试点,满足1≤N≤2×105的数据一定不超过10组,其余数据则满足1≤N≤1000。结果表示为Case#xy,其中x为组别编号(从1开始),y为破纪录的天数。这是最后一天,或者这一天的游客人数严格大于下一天的游客人数。对于测试样例3,第一天、第三天和第六天破了纪录。这一天的游客人数严格大于以前每一天的游客人数。对于测试样例1,第二天和第四天破了纪录。对于测试样例2,只有最后一天破了纪录。请注意,第一天也可以是破纪录的一天。对于测试样例4,没有一天破了纪录。...原创 2022-07-29 21:24:47 · 311 阅读 · 0 评论 -
坠落的蚂蚁(北京大学考研机试题)
每个初始状态由两个整数组成,中间用空格隔开,第一个数字表示初始位置厘米数P,第二个数字表示初始方向,−1表示向左,1表示向右,0表示静止。在某一时刻蚂蚁的位置各不相同且均在整数厘米处(即1,2,3,…99厘米),有且只有一只蚂蚁A速度为0,其他蚂蚁均在向左或向右爬动。第一行包含一个整数表示蚂蚁的个数N,之后共有N行,每一行描述一只蚂蚁的初始状态。它们的速度为每秒一厘米或静止不动,方向只有两种,向左或者向右。三只蚂蚁碰头,则两边的蚂蚁交换速度,中间的蚂蚁仍然静止。...原创 2022-07-29 21:20:18 · 127 阅读 · 0 评论 -
排列数字(DAY90)dfs
bfs空间复杂度O(2^n)数据结构queue队列可以搜到最短路(当权重为1时)dfs空间复杂度O(n)数据结构stack栈不具有最短性。dfsbfs的区别。原创 2022-07-29 10:54:07 · 180 阅读 · 2 评论 -
搜索与图论-树与图的深度优先遍历(DAY 49)
文章目录题目代码题目代码#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int N=1000010,M=N * 2;int n,m;int h[N],e[M],ne[M],idx;bool st[N];int ans=N;void add (int a,int b){ e[idx]=b,ne[idx]=h[a],原创 2022-04-28 21:16:59 · 149 阅读 · 0 评论 -
BFS 题845. 八数码(DAY 45)
文章目录原题题目代码实现原题题目代码实现#include<iostream>#include<algorithm>#include<unordered_map>#include<queue>using namespace std;int bfs(string state){ queue<string>q; unordered_map<string,int> d; q.push(原创 2022-04-24 17:11:21 · 243 阅读 · 0 评论 -
多线程矩阵加速 (DAY 45)
文章目录代码实现结果代码实现#include<stdio.h>#include<stdlib.h>#include<time.h>#include<pthread.h>#define N 1010pthread_t thid[N][N];pthread_t tid[2];pthread_t cid[N];// 行idint pass[N][N][2];int n;int a[N][N], b[N][N];int result[N][N原创 2022-04-24 16:30:54 · 311 阅读 · 0 评论 -
BFS 宽度优先搜索 844. 走迷宫(DAY 45)
文章目录原题题目代码实现走迷宫问题里的向量表达,权值都为1时才能用bfs搜索最短路径,权值不为1,用Dijkstra算法原题题目代码实现//所有边的权重都是1时才能用bfs求最短路 dijstra求权值不同时候的最短路#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef pair<int,int >PII;const int原创 2022-04-24 16:25:33 · 1147 阅读 · 0 评论 -
DFS 题 八皇后问题(DAY 45)
文章目录题目代码实现第一种搜索方法第二种搜索方法题目代码实现第一种搜索方法#include<iostream>using namespace std;const int N=20;int n;char g[N][N];bool row[N],col[N],dg[N],udg[N];void dfs(int x,int y,int s){ if(y==n) y=0,x++; if(x==n) { if(s==n)原创 2022-04-24 15:20:15 · 228 阅读 · 0 评论 -
DFS 842. 排列数字(DAY 45)
文章目录原题题目代码实现原题题目代码实现#include<iostream>using namespace std;const int N=10;int n;int path[N];bool st[N];void dfs(int u){ if(u==n) { for(int i=0;i<n;i++) cout <<path[i]<< ' '; puts(""); return原创 2022-04-24 11:23:56 · 226 阅读 · 0 评论