USACO 1.4 Search Techniques
来源:互联网 发布:橱柜设计软件下载 编辑:程序博客网 时间:2024/05/27 01:14
- n皇后(DFS) 即任意两个皇后都不能处于同一行、同一列或同一斜线上
- 骑士周游问题(BFS) 走马步
- Depth First with Iterative Deepening (IDDFS)
- if the answer is expected to be in the leaves, use the simpler depth first search.
-
IDDFS(wiki)
procedure IDDFS(root) for depth from 0 to ∞ found ← DLS(root, depth) if found ≠ null return foundprocedure DLS(node, depth) if depth = 0 and node is a goal return node else if depth > 0 foreach child of node found ← DLS(child, depth−1) if found ≠ null return found return null
原文
人家的分类
然后我发现wiki里面有一个搜索章节= =
ariprog
查题解过的..罪过罪过
题解是这么说的,枚举每个等差数列前两个判断
所以说,搜索的方法关键在于是否枚举对初始数值
- 好像发现自己被坑在哪了..
- bool数组get后要拿int数组来枚举啊亲= =
//快排算法void quicksort (int array[], int start, int last) { int pivot; if (start < last) { pivot = pivotlist(array, start,last); quicksort (array, start,pivot-1); quicksort (array, pivot+1,last); }}int pivotlist(int array[], int f, int l) { int pivotpoint; int pivotvalue, temp; pivotvalue = array[f]; pivotpoint = f; for (int i = f+1;i<=l; i++) { if (array[i]<pivotvalue) { pivotpoint++; temp = array[i]; array[i] = array[pivotpoint]; array[pivotpoint] = temp; } } temp = array[f]; array[f] = array[pivotpoint]; array[pivotpoint] = temp; return pivotpoint;}
语法trick
- 在函数里面也可以用{ }初始化数组
倒牛奶问题
- 三个杯子,已知容量,最后一个装满,求当第一个空时候最后一个可能取值
- dfs是肯定的,一开始拿六个变量写,然后发现太麻烦了(其实是写到最后一个变量发现dfs顺序很讨嫌,重构,就改成两个数组枚举,用3-a-b来表示剩下的那个
- 但是这样又有个问题,(写题解时候发现根本不是问题= =),就是状态三维数组表示不知道下标,就装逼写了一个hash..
- 然后test2坑了一下为0的情况,就是最后枚举时候last初始值不能设为0
hash
int trans(int *ori){ return ori[0]+ori[1]*21;}
枚举
void dfs(int *nleft){ vis[trans(nleft)]=true; if (nleft[0]==0) {//这里一开始懵逼,以为b满也可以 vs[nleft[2]]=true; } //a=>b int t[3]; for (int a=0; a<3; a++) for (int b=0; b<3; b++) if (nleft[a]&&a!=b&&nleft[b]<bottle[b]) { t[a]=0,t[b]=nleft[b]+nleft[a],t[3-a-b]=nleft[3-a-b];//这里一次倒完,思路比if里面判断要清晰很多 if (t[b]<=bottle[b]) { if (vis[trans(t)]==false) { dfs(t); } }else { t[a]=t[b]-bottle[b]; t[b]=bottle[b]; if (vis[trans(t)]==false) { dfs(t); } } }}
枚举
int last=-1; for (int i=0; i<maxn; i++) { if (vs[i]) { if (last>=0) { fout<<last<<" "; last=i; }else last=i; } }fout<<last<<endl;
题解中的语法trick
State state(int a, int b, int c){ State s; s.a[0] = a; s.a[1] = b; s.a[2] = c; return s;}
State pour(State s, int from, int to){ int amt; amt = s.a[from]; if(s.a[to]+amt > cap[to]) amt = cap[to] - s.a[to]; s.a[from] -= amt; s.a[to] += amt; return s;}
0 0
- USACO 1.4 Search Techniques
- Search Techniques
- Search Techniques
- Search Techniques 搜索方式
- 转载丶Search Techniques
- USACO Section 1.4 More Search Technique
- usaco 1.2 complete search
- USACO Section 1.2 Complete Search
- Techniques
- USACO 之 Section 1.2 Complete Search
- USACO 1.4-Packing Rectangles
- USACO 1.4-The Clocks
- USACO 1.4-Arithmetic Progressions
- usaco 1.4.4
- USACO 1.4 clocks 分析
- USACO Section 1.4 题解
- USACO 1.4.1
- [usaco]1.4 Arithmetic Progressions
- CA服务器的创建和CA客户端认证过程
- linux-信号量
- leetcode279-Perfect Squares
- 基于vivado的fir ip核的重采样设计与实现
- UVA 156
- USACO 1.4 Search Techniques
- unity解决prefab内嵌套prefab,丢失引用关系的问题
- 开发技术组件官网教程清单
- 【hadoop】win7-32位下安装hadoop2.x
- c++编译器何时会生成默认构造函数
- (java) Unique Paths
- oracle之简单的表操作和SQL语句分类
- 【cocos2dx 3.x】锚点不是坐标原点
- hdoj 4497(gcd&lcm分解质因数)