IOI1994 北京2008的挂钟 迭代加深
总的来讲,这是一道很⑨的题,因为:
(1)题目中有⑨个挂钟
(2)有⑨种操作方案
(3)这题因为解空间太小所以可以直接⑨重循环!!
这题可以用迭代加深搜索高效求解,剪枝的策略也很显然:
>所求的操作序列一定是单调不递减的
>同一操作不可能在解中出现4次及以上(操作4次等于没有操作)
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
]={};
]={};
]={};
void move(int _cmd)
{
++cmdCnt[_cmd];
switch(_cmd)
{
: ++dir[]; ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; break;
: ++dir[]; ++dir[]; ++dir[]; ++dir[]; break;
}
}
void undo(int _cmd)
{
--cmdCnt[_cmd];
switch(_cmd)
{
: --dir[]; --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; break;
: --dir[]; --dir[]; --dir[]; --dir[]; break;
}
}
inline bool isDest()
{
;i<=;i++) ) return false;
return true;
}
bool search_aux(int _maxDepth,int _curDepth,int _lastCmd)
{
if(isDest()) return true;
if(_curDepth > _maxDepth) return false;
;i++)
{
)
{
move(i);
,i);
undo(i);
if(next) { ++ans[i]; return true; }
}
}
return false;
}
void input()
{
;i<=;i++) scanf("%d",dir+i);
}
void search()
{
;;i++) ,)) return;
}
void printAns()
{
;i<=;i++)
while(ans[i]--) printf("%d ",i);
}
int main()
{
input();
search();
printAns();
;
}
Cirno is willing to try this problem (*^__^*)
IOI1994 北京2008的挂钟 迭代加深的更多相关文章
- vijosP1016 北京2008的挂钟
vijosP1016 北京2008的挂钟 题目链接:https://vijos.org/p/1016 [思路] Dfs. 对操作搜索更加优秀,所以采用搜索每一个操作的使用次数,因为操作数为4则相当于没 ...
- Vijos——T 1016 北京2008的挂钟 || 洛谷—— P1213 时钟
https://www.luogu.org/problem/show?pid=1213 题目描述 考虑将如此安排在一个 3 x 3 行列中的九个时钟: 目标要找一个最小的移动顺序将所有的指针指向12点 ...
- POJ1129Channel Allocation[迭代加深搜索 四色定理]
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14601 Accepted: 74 ...
- BZOJ1085: [SCOI2005]骑士精神 [迭代加深搜索 IDA*]
1085: [SCOI2005]骑士精神 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1800 Solved: 984[Submit][Statu ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- 迭代加深搜索 codevs 2541 幂运算
codevs 2541 幂运算 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...
- HDU 1560 DNA sequence (IDA* 迭代加深 搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560 BFS题解:http://www.cnblogs.com/crazyapple/p/321810 ...
- usaco4.12Fence Rails(迭代加深)
为了这题还去学了下迭代加深 回来还是不会写 只好参考各大神的代码及题解了 二分枚举最大可以切的块数 然后就是各种分析及优化 USACO题解里写了7个优化.. 问题分析 抽象一下就可以发现,算法的本质是 ...
- poj2286The Rotation Game(迭代加深dfs)
链接 把迭代加深理解错了 自己写了半天也没写对 所谓迭代加深,就是在深度无上限的情况下,先预估一个深度(尽量小)进行搜索,如果没有找到解,再逐步放大深度搜索.这种方法虽然会导致重复的遍历 某些结点,但 ...
随机推荐
- Monkey ‘mk_request_header_process’函数输入验证漏洞
漏洞名称: Monkey ‘mk_request_header_process’函数输入验证漏洞 CNNVD编号: CNNVD-201308-003 发布时间: 2013-08-22 更新时间: 20 ...
- 使用 Chef 管理 Azure 资源
发布于 2014-07-08 作者 陈 忠岳 Chef 是一款开源的开发运营(DevOps)工具,用以应对 IT 基础设施方面的挑战.微软开放技术有限公司(简称"微软开放技术" ...
- 【转】android: 长按删除listview的item
原文网址:http://www.cnblogs.com/nuistlr/archive/2012/09/07/2675649.html 首先要继承OnItemLongClickListener pub ...
- 【转】android 完全退出应用程序
原文网址:http://www.yoyong.com/archives/199 android退出应用程序会调用android.os.Process.killProcess(android.os.Pr ...
- (转载)prepare函数的学习,我要学习php第二天
(转载)http://www.boyuan78.com/htm/company/2012_1030_60.html prepare函数的学习,我要学习php第二天 $mysqli = new mysq ...
- Frontend Development
原文链接: https://github.com/dypsilon/frontend-dev-bookmarks Frontend Development Looking for something ...
- Poj 3468-A Simple Problem with Integers 线段树,树状数组
题目:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- JavaScript 类型判断 —— typeof 以及 instanceof 中的陷阱
JavaScript中基本类型包含Undefined.Null.Boolean.Number.String以及Object引用类型.基本类型可以通过typeof来进行检测,对象类型可以通过instan ...
- 《A First Course in Probability》-chaper3-条件概率和独立性-P(·|F)是概率
条件概率中的三个命题: 下面我们分条来解读一下这三个命题.
- Spring 连接数据库测试
1.编写测试对象类 package model; import java.io.Serializable; /** * Created by xumao on 2016/12/5. */ public ...