The Rotation Game (POJ 2286) 题解】的更多相关文章

The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 6396   Accepted: 2153 Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2…
[问题描述] (由于是英文的,看不懂,这里就把大意给大家说一下吧……都是中国人,相信大家也不愿意看英文……) 如图,一个井字形的棋盘,中间有着1-3任意的数,有ABCDEFGH八个操作,每个操作意味着该操作所在行朝该操作方向整体移动一格,详见图,你的目的是:对于输入的多组数据,用最少的步数使得井字形棋盘中间的八个数为同一个数,若不需操作就已达到要求,则输出“No moves needed”,无论是否需要操作,你都应将中间的数字给输出.输入以一个0结束. [样例输入] 1 1 1 1 3 2 3…
[题目链接] http://poj.org/problem?id=2286 [算法] IDA* [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #inclu…
IDA*算法,即迭代加深的A*算法.实际上就是迭代加深+DFS+估价函数 题目传送:The Rotation Game AC代码: #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <bitset> #include…
感觉这样的算法还是比較局限的吧,反复搜索是一个不好的地方,并且须要高效的估值函数来进行强剪枝,这点比較困难. 迭代搜索深度是一个比較炫酷的搜索方式,只是有点拿时间换空间的感觉. 首先迭代深度比較搓的写法是,首先设置一个阀值MaxH,初始为最小值. 当在搜索深度Depth <= MaxH时找到解则此时为最优解,否则MaxH++,继续深搜. 第二种比較吊的写法是二分搜索深度,若搜到则减小阀值,否则增大阀值. 总之,迭代深度搜索就是通过改变深搜的深度来寻找最优解,这样做的优点是省掉了BFS中状态标记全…
原题 有1234四个数字,每个数字八个.有八种方向的移动,使得操作后中间八个方块的数字相同,求最小操作步数. 对于这种求最小步数的看起来就是dfs的题,就ID-DFS就好了. //不知道为什么都是IDDFS,我的跑的这么慢-- #include<cstdio> #include<vector> using namespace std; int a[30],in[10]={0,7,8,9,12,13,16,17,18},ans,cnt; int chg[5][8]={{0},{0,1…
(再一次感谢学长幻灯片) ID A* 随便自己yy了一下. 额嗯 思路什么的都没有问题 就是改不对.. 无奈地删代码...边删边交. 删啊删 哎呦 AC了 ... ... ... 找删的那一段 . oh 原来 d[i]^1!=f 要改成(d[i]^1)!=f 优先级问题 无奈了.. #include<cstdio> #include<algorithm> using namespace std; char t,a[25],b[25],d[]={0,2,4,7,3,1,6,5},ch…
题目 题意: $ yyf $ 一开始在 $ 1 $ 号节点他要通过一条有 $ n $ 个地雷的道路,每次前进他有 $ p $ 的概率前进一步,有 $ 1-p $ 的概率前进两步,问他不领盒饭的概率. 对于这道题我们可以考虑 $ dp $ ,我们可以设计状态 $ f[i] $ 表示安全通过 $ i $的概率,那么我们可以得到状态转移方程 $ f[i]=p* f[i-1]+(1-p)* f[i-2] $ $ f[x_i]=0 $ 然后我们可以看到 $ x \in [1, 100000000] $如果…
题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 5 11 1 2 3 4 5 输出样例 2 3 解析 我们很容易发现对于这题我们可以二分答案,先找出一个初始长度,判断是否存在合法序列,如果存在缩小长度,如果不存在加长长度. 时间复杂度 $ O(nlogn) $ 代码 #include<cstdio> #include<algorithm…
题目 Given a list of N integers with absolute values no larger than \(10^{15}\), find a non empty subset of these numbers which minimizes the absolute value of the sum of its elements. In case there are multiple subsets, choose the one with fewer eleme…