随笔分类 -  算法竞赛入门

算法竞赛入门经典(第2版) -刘汝佳
摘要:陷入思维定式里面了..以为总是在递归基里面解决问题 阅读全文
posted @ 2017-09-09 22:01 lan126 阅读(180) 评论(0) 推荐(0)
摘要:注意m,n的改变和起始位置和终止位置的改变 阅读全文
posted @ 2017-09-08 23:17 lan126 阅读(176) 评论(0) 推荐(0)
摘要:归并排序 注意递归基 阅读全文
posted @ 2017-09-07 08:56 lan126 阅读(159) 评论(0) 推荐(0)
摘要:分解问题,递归求解,合并解 分成尽量相等的两部分 分别求出完全位于左边的序列和右边的序列 合并即在求出起点位于左边,终点位于右边的序列然后与左右的最优解比较 时间复杂度O(nlogn) 阅读全文
posted @ 2017-09-05 12:19 lan126 阅读(222) 评论(0) 推荐(0)
摘要:总结一下这题的解题步骤: 1.将问题抽象成某种模型,比如这题就是找出一个有d的状态,且要倒水量最小,平时写的都是路径最小 ,用的是普通队列,这题要把倒水量最小考虑进去就需要用优先队列 即:用优先队列的就是在队列中不断找出倒水量最小的状态,然后判断是否一个容器中的水为d 普通队列可以用来求最短路径长度 阅读全文
posted @ 2017-08-31 12:09 lan126 阅读(163) 评论(0) 推荐(0)
摘要:#include #include #include #include using namespace std; typedef long long ll; int maxd; const int maxn=1000000; int best[maxn]; int ans[maxn]; int first(int a,int b) { int it=1; while... 阅读全文
posted @ 2017-08-30 11:26 lan126 阅读(172) 评论(0) 推荐(0)
摘要:#include #include #include #include #include using namespace std; typedef int state[9]; const int maxstate=1000000; state st[maxstate],goal; int dst[maxstate]; int fa[maxstate]; set vis; cons... 阅读全文
posted @ 2017-08-28 21:49 lan126 阅读(113) 评论(0) 推荐(0)
摘要:在网上搜索了一下我的第一种方法应该是减枝的策略,回溯也是减枝的一种 利用stl全排列,这种方法有个缺点就是当情况比较多时会很慢 回溯法实现,还可以给素数打个表 阅读全文
posted @ 2017-08-27 09:26 lan126 阅读(159) 评论(0) 推荐(0)
摘要:看了看以前的shceme版也好有趣 阅读全文
posted @ 2017-08-25 14:51 lan126 阅读(112) 评论(0) 推荐(0)
摘要:思路就是书上写的从小到大取P中值v插到当前,当然v要是没用过的或者说是没用完的 当有重复时要跳过重复的值 利用stl快速实现 阅读全文
posted @ 2017-08-22 16:58 lan126 阅读(117) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 int main() 7 { 8 int k; 9 cin>>k; 10 11 int count=0; 12 13 for(int y=k+1;y=y) 18 printf("1/%d=1/%d+1/%d... 阅读全文
posted @ 2017-08-21 21:36 lan126 阅读(134) 评论(0) 推荐(0)
摘要:思路:用数组存储 然后枚举起点和终点来创建子序列由于乘积很大所以要用long long 同时使用cout输出避免printf不同编译器的不同实现 阅读全文
posted @ 2017-08-21 12:01 lan126 阅读(146) 评论(0) 推荐(0)
摘要:除法 阅读全文
posted @ 2017-08-21 11:29 lan126 阅读(142) 评论(0) 推荐(0)
摘要:Idealpath 双向bfs输出颜色,邻接矩阵实现 邻接表实现最短距离 阅读全文
posted @ 2017-08-20 16:59 lan126 阅读(354) 评论(0) 推荐(0)
摘要:Ideal Path 不熟悉父节点方式 自己先敲了一遍 1.发现需要vis数组来进行mark 2.无论是push过程还是pop过程发现目标节点都可以开始打印,但是push过程如果有多个parent节点会有错误. 不记录父节点的bfs 阅读全文
posted @ 2017-08-19 11:39 lan126 阅读(139) 评论(0) 推荐(0)
摘要:#include #include #include using namespace std; const int maxn=210; char buf[maxn][maxn]; int n; bool isnode(char ch) { if(ch=='-' || ch=='|' || ch==' ' || ch==0 || ch=='\n') retu... 阅读全文
posted @ 2017-08-17 18:04 lan126 阅读(114) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 const int maxn=1000; 9 int UG[maxn][maxn]; 10 int vis[maxn]; 11 char str[1024]; 12 int in[maxn]; ... 阅读全文
posted @ 2017-08-10 19:18 lan126 阅读(118) 评论(0) 推荐(0)
摘要:uva10305 深度优先用来找入度为零0的节点 1.如果是有环的有向图则返回false 实现的代码为第九行 2.利用for循环来对节点间可能的联系进行判断,从而实现在边上移动. 拓扑排序 阅读全文
posted @ 2017-08-08 15:54 lan126 阅读(163) 评论(0) 推荐(0)
摘要:uva 816 阅读全文
posted @ 2017-08-07 17:28 lan126 阅读(193) 评论(0) 推荐(0)
摘要:图:油田 阅读全文
posted @ 2017-08-05 23:18 lan126 阅读(124) 评论(0) 推荐(0)