
算法--基础算法
runnerxin
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
算法笔记--深度搜索
1、N皇后问题在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。#include<stdio.h> int hang[300][300]= {0,0}; int lie[30]= {0}; int cnt=0; int ans[30][30]; void so原创 2017-06-28 19:37:11 · 331 阅读 · 0 评论 -
算法笔记--宽度优先搜索
poj 2312 Battle City思路:从Y到T的最小turn。turn:走一步路算一种,开炮也算一种。 B:土墙,可以被炮打坏,打坏以后就不在了。 R:河流,不能通过。 S:铁墙:不能通过,也不能被炮弹打坏。 E:空格,可以直接走过去。因此,用优先队列,每次取出turn最小的那个,进行操作。知道走到T为止。因为土墙可以仙贝打坏,在通过,因此如果遇到土墙,可以认为进项了两个turn,原创 2017-06-28 19:43:07 · 382 阅读 · 0 评论 -
算法笔记--分治(求后序遍历)
由前序遍历和中序遍历求后序遍历Sample Input 9 1 2 4 7 3 5 8 9 6 4 7 2 1 8 5 9 3 6 Sample Output 7 4 2 8 9 5 6 3 1 #include<cstdio> int qian[1005],zhong[1005]; void ecs(int a,int b,int n,int flag) //在前序是第几个,在中序是第几原创 2017-06-28 20:00:31 · 285 阅读 · 0 评论 -
算法笔记--贪心(田忌赛马)
hdu1952 Tian Ji – The Horse RacingSample Input 3 92 83 71 95 87 74 2 20 20 20 20 2 20 19 22 18 0 Sample Output 200 0 0 #include<cstdio> #include<cmath> #include<cstring> #include<iostream>原创 2017-06-28 20:03:41 · 365 阅读 · 0 评论 -
算法笔记--二分/三分
while(left<=right){ int mind=(left+right)>>1; if(...) return x; else if(...) left=mind+1; else right=mind-1; } 或 int temp=left; while(left<=right){ int mind=(left+right)>>1; if(原创 2017-06-28 20:25:01 · 598 阅读 · 0 评论