搜索
经典搜索
Wa_Automata
这个作者很懒,什么都没留下…
展开
-
2023河南萌新联赛第(一)场:河南农业大学 H - 迷宫探险
在与boss的最终决战之后,小蓝来到了冒险的最后一关,在他面前有一个n*m的迷宫,迷宫中道路用'.'表示,墙壁则由‘#’表示。小蓝初始在[1,1]的位置,他只有到达[n,m]才能开启最终的宝藏。小蓝现在迫不及待的想要开启宝藏,所以他想最短的时间内走出迷宫。现在迷宫内有一种特殊的装置 –“弹射器”。弹射器的格子用’*’表示。当走到有弹射器的一格时,小蓝必须选择一个方向,弹射器会让他沿着这个方向弹射x个距离,不同弹射器的弹射距离可以不同。弹射后的格子如果超过迷宫边界或者是墙壁则不能选择这个方向。原创 2023-07-22 08:08:17 · 91 阅读 · 0 评论 -
2023河南萌新联赛第(一)场:河南农业大学 D - 松鼠回家
松鼠宝宝由于贪玩去了一个具有n个点和m条边的无向图中,现在松鼠宝宝仅有h点体力,所有的边经过一次后会消耗部分体力,同时松鼠爸爸为了惩罚贪玩的松鼠宝宝,每到一个点会扣除部分松果(起点的松果也会扣除)。现松鼠宝宝向你求助,询问在能到达家的情况下。(分别无向图的点数,边数,起点位置,家的位置,开始时候的体力)尽可能让路径上扣除松果的数量最大的那个点扣除的数量尽可能小。输出一行代表最大扣除数量的最小值,若无法到达,则输出。(分别代表无向边的两点和路上所消耗的体力)(每个点所扣除的松果数量)原创 2023-07-21 19:35:34 · 71 阅读 · 0 评论 -
PTA L2-048 寻宝图 (25 分)
给定一幅地图,其中有水域,有陆地。被水域完全环绕的陆地是岛屿。有些岛屿上埋藏有宝藏,这些有宝藏的点也被标记出来了。本题就请你统计一下,给定的地图上一共有多少岛屿,其中有多少是有宝藏的岛屿。原创 2023-04-24 13:16:51 · 2577 阅读 · 3 评论 -
PTA L2-038 病毒溯源 (25 分)
将所有节点的子节点从小到大排序,在选择的时候只会更长,且字典序最小的更新。原创 2023-03-23 10:35:49 · 460 阅读 · 0 评论 -
HDU - 1240 Asteroids!(三维BFS)
# [HDU - 1240 Asteroids!(三维BFS)](https://acm.hdu.edu.cn/showproblem.php?pid=1240)题目大意:- 给定的三维空间内,每次只能走一格。- `X`属于障碍物,不能走- 问从`[A,B,C]`到`[D,E,F]`最快需要几步原创 2023-02-11 21:07:26 · 342 阅读 · 0 评论 -
HDU - 4277 USACO ORZ(DFS+Set)
# [HDU - 4277 USACO ORZ](https://acm.hdu.edu.cn/showproblem.php?pid=4277)### 题意:给你n条篱笆,问你可以组成多少个不同的三角形,一边不同即为不同,需要注意的是n条篱笆一起组成一个三角形,而不是在里面选3条组成一个三角形### 解题思路:利用dfs枚举出所有情况,然后利用set去掉重复的原创 2022-12-29 22:29:24 · 72 阅读 · 0 评论 -
ZZULIOJ 2981: 章节二:偶遇达达尼昂
# [ZZULIOJ 2981: 章节二:偶遇达达尼昂](http://acm.zzuli.edu.cn/problem.php?id=2981)题目描述:简单来说就是将每个物品分给四个人,然后怎样分之后,最长的花费时间最短。我们这里可以考虑状态压缩,或者 $DFS$ 爆搜。都可以实现。时间复杂度:$4^{n}$原创 2022-11-21 19:02:02 · 87 阅读 · 0 评论 -
Problem H. 旋转水管
# [Problem H. 旋转水管](https://codeforces.com/gym/103941) - `DFS`搜索。 - 水管出水状态和进入状态相关,故需要记录上一个格子流入下一个格子时的状态。 - 分析状态可知: - 对于 `I` 形的水管,流出状态和流入状态相同。 - 对于 `L` 形的水管,当流入状态是 $\uparrow$ 或 $\downarrow$ 时,流出时都有两种状态 $\leftarrow$ 和 $\rightarrow$;当流入状态是 $\leftarrow$原创 2022-10-10 15:28:14 · 365 阅读 · 0 评论 -
PTA L3-032 关于深度优先搜索和逆序对的题应该不会很难吧这件事 (30 分)
背景知识深度优先搜索与 DFSDFSDFS 序深度优先搜索算法(DFS)(DFS)(DFS)是一种用于遍历或搜索树或图的算法。以下伪代码描述了在树 TTT 上进行深度优先搜索的过程:令 rrr 为树 TTT 的根,调用 DFS(T,r,L)DFS(T,r,L)DFS(T,r,L) 即可完成对 TTT 的深度优先搜索,保存在链表 LLL 中的排列被称为 DFSDFSDFS 序。相信聪明的你已经发现了,如果枚举子节点的顺序不同,最终得到的 DFSDFSDFS 序也会不同。逆序对给定一个长度为 nnn原创 2022-06-20 23:26:14 · 1287 阅读 · 1 评论 -
HDU - 1495 非常可乐(BFS,数学)
HDU - 1495 非常可乐(BFS,数学)巨佬的数学解法#include<iostream>using namespace std;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ int a,b,c; while(cin>>a>>b>>c&&(a&&b&&c)) { a/=gcd(b,c); if(a&原创 2022-03-11 10:50:01 · 352 阅读 · 0 评论 -
POJ - 3414 Pots(BFS)
POJ - 3414 Pots(BFS)#include<iostream>#include<queue>using namespace std;typedef pair<int,int> PII;string s[105][105], ans;bool dist[105][105];int main(){ int a,b,c;cin>>a>>b>>c; queue<PII> q; q原创 2022-03-09 15:14:16 · 84 阅读 · 0 评论 -
POJ - 1321 棋盘问题(DFS,递归与回溯)
POJ 1321 棋盘问题#include<cstdio>#include<cstring>char g[10][10];int n,k,ans,col[10];void dfs(int u,int cnt){ if(cnt==k)//如果此时满了,即使装满了,就ans++ { ans++; return; } if(u==n) return; dfs(u+1,cnt);//这一行不放棋子原创 2022-03-09 14:54:21 · 206 阅读 · 0 评论 -
UVA - 11624 Fire(BFS)
UVA - 116241.先求出所有格子被火覆盖的最短时间(多源bfs, 有多个火种)2.再从起点开始bfs, 只要我到达这个格子的时间 严格小于 这个格子被火覆盖的时间,就能走到这个格子3.走到边界的空地就返回#include<cstdio>#include<cstring>#include<queue>#include<vector>using namespace std;typedef pair<int,int> PI原创 2022-03-07 17:36:57 · 149 阅读 · 0 评论 -
POJ - 3279 Fliptile(状态压缩)
POJ - 3279 Fliptile#include<cstdio>#include<cstring>const int N = 20;const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};int n, m, ansf = 0;int g[N][N], b[N][N], ans[N][N];void turn(int x, int y) //翻转函数{ b[x][y] ^= 1; for (int i =原创 2022-03-01 20:28:18 · 126 阅读 · 0 评论 -
POJ - 2251 Dungeon Master(三维BFS)
POJ - 2251 Dungeon Master(三维BFS)http://poj.org/problem?id=2251题意: 给定一个三维空间,一个起点和终点,还有若干障碍物,人物从起点开始,只能往上下左右前后六个方向移动,问能否达到终点,若能,输出最短步数#include<iostream>#include<cstring>#include<queue>using namespace std;const int dx[]={-1,1,0,0,0,0}原创 2022-03-01 19:47:11 · 117 阅读 · 0 评论 -
POJ - 1426 Find The Multiple(DFS)
POJ - 1426 Find The Multiple#include<cstdio>int n,f;void dfs(long long m,int step){ if(f||step>18) return; if(m%n==0) { printf("%lld\n",m); f=1; } dfs(m*10,step+1); dfs(m*10+1,step+1);}int main(){原创 2022-02-13 16:56:06 · 208 阅读 · 0 评论 -
POJ - 3126 Prime Path(线性筛+BFS)
POJ - 3126 Prime Path(BFS)#include<cstdio>#include<cstring>#include<queue>using namespace std;int dist[10010],primes[10010],st[10010],cnt;void get_primes() // 线性筛质数{ for (int i = 2; i <= 10000; i ++ ) { if (!s原创 2022-02-11 00:41:26 · 306 阅读 · 0 评论 -
HDU - 2612 Find a way(双向BFS)
https://vjudge.net/problem/HDU-2612http://acm.hdu.edu.cn/showproblem.php?pid=2612#include<iostream>#include<cstring>#include<queue>using namespace std;typedef pair<int,int> PII;const int N = 210;char g[N][N];int n,m,dist[N原创 2022-02-10 23:48:21 · 310 阅读 · 0 评论 -
POJ - 3662 Telephone Lines(双端队列+二分)
POJ - 3662 Telephone Lines题目描述到nnn有kkk条边可以免费升级,因此只需要求111~NNN的所有路径中第kkk + 111大的值的最小值,是最大最小值模型,因此可以使用二分求解对于区间[0,1000001][0,1000001][0,1000001]中的某一个点xxx:check(x)check(x)check(x)函数表示:::从111走到NNN,最少经过的长度大于xxx的边数的数量是否小于等于kkk,若是则返回truetruetrue,否则返回falsefa原创 2022-01-20 16:22:23 · 308 阅读 · 0 评论 -
POJ - 2044 Weather Forecast(BFS)
POJ - 2044 Weather Forecast#include<cstdio>#include<cstring>#include<queue>#include<vector>using namespace std;const int N = 366;const int dx[]={-1,0,1,0,0},dy[]={0,1,0,-1,0};int n;bool st[N][3][3][7][7][7][7];int state原创 2022-01-20 00:00:06 · 312 阅读 · 0 评论 -
POJ - 1167 The Buses(DFS,迭代加深,剪枝)
POJ - 1167 The Buses(DFS,迭代加深,剪枝) O(CC60217)O(C_{C_{60}^2}^{17})O(CC60217)首先预处理出所有可能的线路。先枚举起点i,再枚举公差j,则i和j需要满足两个条件:由于i是起点,因此0 ~ i - 1中不能包含任何该序列的点,所以公差j至少是i + 1;由于0 ~ 59之间至少要包含两个点,因此i + j一定小于60;剩下的问题变成:最少从合法线路中选出多少条,才可以覆盖所有给定的公交车。由于总路线数量较多,最多原创 2022-01-19 01:16:37 · 130 阅读 · 0 评论 -
POJ - 3700 Missile Defence System(DFS,迭代加深,剪枝,贪心)
POJ - 3700 Missile Defence System(DFS,迭代加深,剪枝,贪心) O(n2n)O(n2^n)O(n2n)为了能遍历所有情况,我们首先考虑搜索顺序是什么。搜索顺序分为两个阶段:从前往后枚举每颗导弹属于某个上升子序列,还是下降子序列;如果属于上升子序列,则枚举属于哪个上升子序列(包括新开一个上升子序列);如果属于下降子序列,可以类似处理。分别记录当前每个上升子序列的末尾数up[],和下降子序列的末尾数down[]。这样在枚举时可以快速判断当前数是否可以接在某原创 2022-01-19 01:04:56 · 399 阅读 · 0 评论 -
POJ - 1084 Square Destroyer(IDA*算法)
POJ - 1084 Square Destroyer#include <cstdio>#include <cstring>#include <vector>using namespace std;const int N = 61; // 网格最大是 5 * 5 的,其中最多会有 5 * (5 + 1) * 2 = 60 个正方形,所以要开到 61int n, idx; // n 为网格规模,idx 为正方形数量int原创 2022-01-18 12:46:26 · 414 阅读 · 0 评论 -
POJ - 2286 The Rotation Game(IDA*, DFS)
POJ - 2286 The Rotation Game#include <cstdio>#include <cstring>const int N = 24;int q[N];int op[8][7] ={ {0, 2, 6, 11, 15, 20, 22}, {1, 3, 8, 12, 17, 21, 23}, {10, 9, 8, 7, 6, 5, 4}, {19, 18, 17, 16, 15, 14, 13}, {23, 21, 17, 12,原创 2022-01-17 23:47:11 · 231 阅读 · 0 评论 -
POJ - 3460 Booksort (IDA*算法)
POJ - 3460 Booksort (IDA*)(IDA*) O(5604)O(560^4)O(5604)时间复杂度理论上最多搜索 5604560^45604 个状态,使用IDA*后实际搜索的状态数量很少。#include <cstdio>#include <cstring>int n,q[15],w[5][15];int f(){ int res=0; for(int i=0;i+1<n;i++) if(q[i+1原创 2022-01-17 22:40:30 · 193 阅读 · 0 评论 -
POJ - 1077 Eight(A∗算法)
POJ - 1077 Eight(A∗算法)#include<iostream>#include<algorithm>#include<map>#include<queue>#define x first#define y secondusing namespace std;typedef pair<int,string> PIS;typedef pair<char,string> PCS;int f(原创 2022-01-17 22:17:08 · 425 阅读 · 0 评论 -
POJ - 2449 Remmarguts‘ Date(A∗优化算法)
POJ - 2449 Remmarguts’ DateA∗A∗A∗ 优化算法采用DijkstraDijkstraDijkstra最短路思想,每次扩展最短的路径,第 kk 次到达终点时的路径长度即为第 kkk 短路的长度。由于算法相当于同时进行 kkk 次单元最短路,时间和空间都可能会超限,因此 预处理每个点到终点的最短距离作为估价函数,利用 A∗A∗A∗ 算法优化。复杂度为 O(nklogn)O(nklogn)O(nklogn)。#include<cstdio>#includ原创 2022-01-17 19:02:55 · 100 阅读 · 0 评论 -
HDU - 3085 Nightmare Ⅱ(双向BFS+曼哈顿距离)
HDU - 3085 Nightmare Ⅱ#include <cstring>#include <iostream>#include <algorithm>#include <queue>using namespace std;typedef pair<int, int> PII;const int N = 810;int n, m;char g[N][N];int st[N][N];PII ghost[2];原创 2022-01-17 15:29:44 · 321 阅读 · 0 评论 -
POJ - 3322 Bloxorz I(BFS)
POJ - 3322 Bloxorz I#include<cstdio>#include<cstring>#include<queue>using namespace std;struct State{ int x,y,lie;};const int N = 510;int n,m;char g[N][N];int dist[N][N][3];bool check(int x,int y){ if(x<0||x>=原创 2022-01-15 00:26:06 · 128 阅读 · 0 评论 -
POJ - 2248 Addition Chains(迭代加深)
POJ - 2248 Addition Chains#include <iostream>#include <algorithm>using namespace std;const int N = 110;int n;int path[N];bool dfs(int u, int k){ if (u == k) return path[u - 1] == n; bool st[N] = {0}; for (int i = u原创 2022-01-14 13:06:45 · 120 阅读 · 0 评论 -
POJ - 1635 Subway tree systems(树的最小表示)
POJ - 1635 Subway tree systems#include<iostream>#include<algorithm>#include<vector>using namespace std;string dfs(string &a, int &u){ u++; vector<string> b; while(a[u]=='0') b.push_back(dfs(a,u)); u+原创 2022-01-12 16:42:12 · 191 阅读 · 0 评论 -
ZZULIOJ 1405: Red and Black,Java(BFS)
1405: Red and Blackimport java.io.*;import java.util.*;public class Main { static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static原创 2022-01-01 00:41:24 · 199 阅读 · 0 评论 -
ZZULIOJ 2746: 布丁(BFS)
2746: 布丁#include<bits/stdc++.h>#define x first#define y secondusing namespace std;typedef pair<int,int>PII;const int N = 510;int dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}};int a[N][N],dist[N][N];int n,m;int bfs(int dx,int dy){ memset(原创 2021-12-24 12:26:55 · 169 阅读 · 0 评论 -
ZZULIOJ 2827: 欢度佳节(状态压缩)
ZZULIOJ 2827: 欢度佳节对于17个连通块,进行爆搜,一共2172^{17}217种情况,状态压缩的思想,用01表示是否走这个连通块,然后DFS暴力搜索,判断能否完成所有的连通块#include<bits/stdc++.h>using namespace std;typedef pair<int,int> PII;const int N = 6;const int x[] = {1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,5};const原创 2021-12-17 19:55:51 · 350 阅读 · 0 评论 -
POJ - 2411 Mondriaan‘s Dream(状态压缩DP+DFS爆搜)
POJ - 24111. 所谓的状态压缩DP,就是用二进制数保存状态。为什么不直接用数组记录呢?因为用一个二进制数记录方便作位运算。前面做过的八皇后,八数码,也用到了状态压缩。2. 本题等价于找到所有横放 1 X 2 小方格的方案数,因为所有横放确定了,那么竖放方案是唯一的。3. 用f[i][j]记录第i列第j个状态。j状态位等于1表示上一列有横放格子,本列有格子捅出来。转移方程很简单,本列的每一个状态都由上列所有“合法”状态转移过来f[i][j] += f[i - 1][k]4. 两个转移条件:原创 2021-07-29 15:52:01 · 178 阅读 · 0 评论 -
HDU - 1010 Tempter of the Bone(DFS)
HDU 1010 Tempter of the Bone#include<iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};string e[30];int book[30][30];int n,m,t,ex,ey,sx,sy,flag;void dfs原创 2021-07-18 20:51:07 · 76 阅读 · 0 评论 -
AcWing 188. 武士风度的牛
AcWing 188. 武士风度的牛#include<iostream>#include<cstring>#include<queue> #define x first#define y secondusing namespace std;typedef pair<int,int>PII;string e[110];int dist[110][110];int n,m;void read(int &x) {原创 2021-07-17 18:57:18 · 82 阅读 · 0 评论 -
POJ - 3287 Catch That Cow(BFS)
HDU - 2717 Catch That Cow#include<iostream>#include<cstring>#include<algorithm>using namespace std;int book[200010];int n,k;struct note{ int x,s;}que[200010];void bfs(){ memset(book,0,sizeof book); int head,tail,flag,tx; he原创 2021-07-16 19:54:19 · 114 阅读 · 0 评论 -
计蒜客 T1212 仙岛求药
计蒜客 T1212 仙岛求药#include<iostream>#include<cstring>#include<queue>using namespace std;struct note{ int x,y,s;}q[100010];string e[30];int book[30][30];int dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}};int n,m,dx,dy,sx,sy;int bfs(int原创 2021-07-15 14:38:09 · 213 阅读 · 0 评论 -
HDU - 1372 Knight Moves(BFS)
HDU - 1372 Knight Moves#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a1,b1,a2,b2;char s1[5],s2[5];int dir[8][2]= {{2,1},{-2,1},{1,2},{1,-2},{2,-1},{-2,-1},{-1,2},{-1,-2}};struct note { int x,y,s;};原创 2021-07-15 14:34:44 · 70 阅读 · 0 评论