CF995E Number Clicker (双向BFS)】的更多相关文章

题目链接(洛谷) 题目大意 给定两个数 \(u\) , \(v\) .有三种操作: \(u=u+1(mod\) \(p)\) . \(u=u+p−1(mod\) \(p)\) . \(u=u^{p−2}(mod\) \(p)\) . 思路 BFS 状态太多导致队列装不下. 迭代加深 \(TLE\) ,浪费了太多时间在每一层上,没有记忆化且状态很多. IDA* 不行,无法得出乐观股价函数. 双向BFS 这样会将步数很为两半,状态相较于普通的 \(BFS\) 会少很多. 先来看操作一和操作二,他们的…
CF995E Number Clicker 题目描述 Allen is playing Number Clicker on his phone. He starts with an integer u u on the screen. Every second, he can press one of 3 buttons. Turn \(u \to u+1 \pmod{p}\). Turn \(u \to u+p-1 \pmod{p}\). Turn \(u \to u^{p-2} \pmod{…
题目分析 首先,我们必须明白,操作都是互逆的,\(1,2\)之间是可以互相转化的,这是不需证明的,对于操作\(3\),实际上,是求当前数的逆元,我们知道,逆元就是求当前数在模另一个数下的倒数,那么,逆元的逆元就是他本身也就是倒数的倒数 于是,所有的操作是可以转化的,对于搜索,其实就有用双向\(bfs\)的依据 采用此算法,需要注意,反向的操作需要转化为现在的正向操作 其实,一共也不会运算超过五秒的时间 #include <bits/stdc++.h> using namespace std;…
双向bfs  注意数很大  用map来存 然后各种难受....…
题意:给出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…
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…