随笔分类 -  搜索

 
HDU 4771
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4771给一个地图,@是起点,给一些物品坐标,问取完所有物品的最小步数,不能取完输出-1物品数最多只有四个,状态压缩一下bfs即可#include #include #include #include #inclu... 阅读全文
posted @ 2015-06-18 23:31 LegendaryAC 阅读(309) 评论(0) 推荐(0)
HDU 1254
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1254暴搜,状态是四维的(箱子和人的坐标),向一个方向推箱子还要判断人能否走到推的位置,1A#include #include #include #include using namespace std;int n... 阅读全文
posted @ 2015-02-01 17:16 LegendaryAC 阅读(231) 评论(0) 推荐(0)
HDU 1429
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1429经典的找钥匙开门走迷宫问题,把钥匙状态压缩一下,然后对迷宫bfs#include #include #include #include #include using namespace std;int n,m... 阅读全文
posted @ 2014-11-23 15:26 LegendaryAC 阅读(136) 评论(0) 推荐(0)
HDU 1026
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1026记录bfs路径,用一个数组记录next前驱的方向,然后递归的时候减回去即可#include #include #include #include using namespace std ;const int ... 阅读全文
posted @ 2014-10-30 11:20 LegendaryAC 阅读(172) 评论(0) 推荐(0)
HDU 1044
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1044代码题,没什么好说的,先预处理出两点间距离,然后dfs搜一下找最大值#include #include #include #include using namespace std;const int INF=... 阅读全文
posted @ 2014-10-29 21:35 LegendaryAC 阅读(453) 评论(0) 推荐(0)
HDU 5025
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5025蛇最多只有五条,状态压缩一下,vis增加两维,表示取得钥匙的状态和蛇的状态,然后一个优先队列的bfs即可解决问题,简单题#include #include #include #include #include... 阅读全文
posted @ 2014-09-24 14:28 LegendaryAC 阅读(511) 评论(0) 推荐(0)
HDU 5040
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5040题意比较难懂,有摄像头的位置是可以走的,每回合开始看做人先走摄像头再转,也就是说如果你这回合走之前没有摄像头在照你,走之后摄像头转过来被照,时间也只是+1,而不是+3(伪装是瞬间完成的)解法显而易见,一个优先... 阅读全文
posted @ 2014-09-23 14:18 LegendaryAC 阅读(365) 评论(0) 推荐(0)
ZOJ 3811
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5343网络赛这水题没写过太伤了,赛后写了下1A。当时钻牛角尖一定要用k次bfs,其实一次就够了,把扩展到的节点插入set中,复杂度nlogn#include #include #i... 阅读全文
posted @ 2014-09-10 10:44 LegendaryAC 阅读(177) 评论(0) 推荐(0)
HDU 4848
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4848题意:求遍历所有点的最小值(这个答案是加i点到起始点的距离,不是当前点到i的距离),必须在ti[i]前到达i点题解:暴搜,剪枝是((当前值>ans)&&(当前点到未到点的时间加上起点到当前点的时间大于未到点的... 阅读全文
posted @ 2014-09-02 02:39 LegendaryAC 阅读(560) 评论(0) 推荐(0)
数位dp
摘要:http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html写得够好了个人习惯从1计数。。无伤大雅。。dp数组最开始memset成-1一次就够了int dfs(int i,int s,int e){ if(!i)return s==target_s ; if(!e && dp[i][s]!=-1)return dp[i][s] ; int u=e?digit[i]:9 ; int res=0 ; for(int d=0 ;d<=u ;d++) res+=dfs(i-1,new_s,e &&... 阅读全文
posted @ 2014-02-06 19:03 LegendaryAC 阅读(137) 评论(0) 推荐(0)
HDU 数位dp
摘要:模板http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html完全理解以后,我发现这种写法实在是太厉害了,简洁,优美,可以回避很多细节问题,而这些细节如果用递推的方法写,处理起来可能会非常痛苦http://acm.hdu.edu.cn/showproblem.php?pid=2089不要62http://www.cnblogs.com/xiaohongmao/p/3473599.html前几天写过这道题的解题报告,两种解法都有http://acm.hdu.edu.cn/showproblem.php?pid=3555不要49#in 阅读全文
posted @ 2014-02-06 18:58 LegendaryAC 阅读(188) 评论(0) 推荐(0)
HDU 1043
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1043http://www.cnblogs.com/goodness/archive/2010/05/04/1727141.html根据这篇文章说的八数码八境界,我这种做法大概是在境界三。。我选择的是康托展开作为哈希函数,在全排列问题中这个哈希函数可以很好的处理冲突http://zh.wikipedia.org/zh/%E5%BA%B7%E6%89%98%E5%B1%95%E5%BC%80当然白书上的那种哈希也是极好的。。#include #include #include using namespace s 阅读全文
posted @ 2014-01-23 10:15 LegendaryAC 阅读(653) 评论(0) 推荐(0)
不想兜圈的老爷爷
摘要:http://oj.luogu.org:8888/problemshow.php?pid=1992水题,yes和no大小写的问题wa了10分钟没看出来,果然该去睡觉了。。问图是否存在环,标号法,dfs把所有点搜一遍,方法见白书P111拓扑排序感觉他们这题出的真逗,最后还乱入个快速幂,OTZ#incl... 阅读全文
posted @ 2013-12-29 14:00 LegendaryAC 阅读(235) 评论(0) 推荐(0)
369C Valera and Elections
摘要:http://codeforces.com/problemset/problem/369/C树的遍历,dfs搜一下,从根节点搜到每个分叉末尾,记录一下路况,如果有需要修复的,就把分叉末尾的节点加入答案10w个点要用邻接表存图#include using namespace std ;typedef struct L{ int s,t ; int v ; int nxt ; }L ;L e[200005] ;int head[100005] ;int cnt ;void ins(int s,int t,int v){ e[cnt].t=t ; e[cnt].v=(v... 阅读全文
posted @ 2013-12-28 23:42 LegendaryAC 阅读(217) 评论(0) 推荐(0)
HDU 3345
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3345最近重写usaco压力好大,每天写的都想吐。。水一道bfs注意的是开始旁边有敌人可以随便走,但是一旦开始走,再与敌人相邻行动力就变为0#include #include #include #include #include #include #include using namespace std ;char map[101][101] ;char ans[101][101] ;int vis[101][101] ;int n,m,MV ;typedef struct L{ int x,y ; ... 阅读全文
posted @ 2013-12-18 22:51 LegendaryAC 阅读(232) 评论(0) 推荐(0)
HDU 1238
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1238考察基本功的题目,把字符串按长度排序之后暴力即可0的情况需要特判,wa1次脑残没删注释,wa N次。。。#include using namespace std ;typedef struct L{ char s[101] ; int l ;}L ;L kk[101] ;int cmp(L a,L b){ return a.l=0 ;i--) { int idx=0 ; if(flag) break... 阅读全文
posted @ 2013-11-21 15:07 LegendaryAC 阅读(169) 评论(0) 推荐(0)
HDU 2102
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2102中文题,开始以为要时间恰好,写个dfs超时,加个奇偶剪枝还超时,然后疯了问了sx,知道要小于等于那个时间就可以,当时吐血到了传送点必须传送有个trick是从'#'跳到'#'这种情况不能走#include #include using namespace std ;typedef struct L{ int x,y,f ; int step ;}L ;int n,m,t ;char map[2][11][11] ;int vis[2][11][11] ;int dir[4] 阅读全文
posted @ 2013-11-14 17:50 LegendaryAC 阅读(758) 评论(0) 推荐(0)
POJ 1088 滑雪
摘要:http://poj.org/problem?id=1088dp的方法实在卡的不会做。。。搜索搞了View Code #include <iostream>using namespace std ;int map[101][101],dp[101][101] ;int r,c ;int dfs(int x,int y){ int tab[4][2]={1,0,-1,0,0,1,0,-1} ; if(dp[x][y]) return dp[x][y] ; int maxx=0 ; for(int i=0;i<4;i++) { int xx... 阅读全文
posted @ 2012-07-23 15:57 LegendaryAC 阅读(137) 评论(0) 推荐(0)
HDU 1240 Asteroids!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1240给这道题跪了,z是x,x是y,y是z,囧View Code #include <iostream>using namespace std ;char map[15][15][15] ;int dp[15][15][15] ;int q[15*15*15][3] ;int n ;int sx,sy,sz ;int ex,ey,ez ;void bfs(){ int x,y,z,xx,yy,zz ; int front=0,rear=1 ; int tab[][3]={1,0,0,-1,0... 阅读全文
posted @ 2012-06-08 01:10 LegendaryAC 阅读(269) 评论(0) 推荐(0)
HDU 2625 Say love to you once again
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2625随便写出一个dfs然后猥琐随机化法剪枝,第一次AC的战绩是1/18,还跑了700+ms,随机50w次成功率还这么低。。。最近rp真是太烂了有木有。。。View Code #include <iostream>#include <cstdlib>#include <ctime>using namespace std ;int map[30][30] ;int n ;int ans ;int vis[30] ;void dfs(int d){ if(d==n) { int 阅读全文
posted @ 2012-06-07 10:12 LegendaryAC 阅读(296) 评论(0) 推荐(0)