双向bfs  注意数很大  用map来存 然后各种难受....…
链接 大意: 给定模数$p$, 假设当前在$x$, 则可以走到$x+1$, $x+p-1$, $x^{p-2}$ (mod p), 求任意一条从u到v不超过200步的路径 官方题解给了两个做法, 一个是直接双端搜索, 复杂度大概$O(\sqrt PlogP)$ 还有一种方法是求出两条u->1, v->1长度不超过100的路径, 通过随机生成一个数x, 再对$(ux(mod P), u)$做欧几里得算法 操作2相当于减法, 操作三相当于交换 大概写了下双端搜索 #include <iost…
题意:给出u,v,p,对u可以进行三种变化: 1.u=(u+1)%p ; 2.u = (u+p-1)%p;  3.u = 模p下的逆元.问通过几步可以使u变成v,并且给出每一步的操作. 分析:朴素的bfs或dfs会超时或炸栈,考虑用双向bfs头尾同时搜.用map存每个数的访问状态和对应的操作编号,正向搜步长为正,反向搜步长为负.反向搜的时候要注意对应加减操作是反过来的. #include<stdio.h> #include<iostream> #include<cstring…
题目链接(洛谷) 题目大意 给定两个数 \(u\) , \(v\) .有三种操作: \(u=u+1(mod\) \(p)\) . \(u=u+p−1(mod\) \(p)\) . \(u=u^{p−2}(mod\) \(p)\) . 思路 BFS 状态太多导致队列装不下. 迭代加深 \(TLE\) ,浪费了太多时间在每一层上,没有记忆化且状态很多. IDA* 不行,无法得出乐观股价函数. 双向BFS 这样会将步数很为两半,状态相较于普通的 \(BFS\) 会少很多. 先来看操作一和操作二,他们的…
E - Number Clicker 思路:双向搜索 代码: #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1…
Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 886    Accepted Submission(s): 185 Problem Description Last night, little erriyue had a horrible nightmare. He dreamed that he and hi…
Solitaire is a game played on a chessboard 8x8. The rows and columns of the chessboard are numbered from 1 to 8, from the top to the bottom and from left to right respectively.There are four identical pieces on the board. In one move it is allowed to…
Problem UVA1601-The Morning after Halloween Accept: 289 Submit: 3136 Time Limit: 12000 mSec  Problem Description  Input  Output For each dataset in the input, one line containing the smallest number of steps to restore ghosts into the positions where…
The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's…
Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3012    Accepted Submission(s): 856 Problem Description Last night, little erriyue had a horrible nightmare. He dreamed that he and h…