文章分类 -  搜索(基础篇)

1
acm的基础搜索题目
摘要:和hdu1175 ( 连连看 )差不多,不过这题可以在边边连#include <stdio.h>#include <string.h>#include <queue>using namespace std;#define MAXSIZE 105struct QNode{ int x,y,d,turns;};queue<QNode> que;const... 阅读全文
posted @ 2010-08-31 16:16 菜到不得鸟 阅读(176) 评论(0) 推荐(0)
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=438#include <stdio.h>#include <string.h>#define MAXSIZE 12struct coor{ int x,y,z; int time;}que[MAXSIZE*MAXSIZE*MAXSIZE];const in... 阅读全文
posted @ 2010-08-27 22:58 菜到不得鸟 阅读(138) 评论(0) 推荐(0)
摘要:比二维的多了2个方向而已,530MS#include <stdio.h>#include <string.h>#include <cmath>using namespace std;#define MAXSIZE 51struct coor{ int x,y,z; int time;}que[MAXSIZE*MAXSIZE*MAXSIZE];const int ... 阅读全文
posted @ 2010-08-27 22:25 菜到不得鸟 阅读(335) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <vector>#include <algorithm>using namespace std;#define MAXLEN 22#define MAXSON 28typedef struct TNode{ T... 阅读全文
posted @ 2010-08-25 22:58 菜到不得鸟 阅读(288) 评论(0) 推荐(0)
摘要://暴搜也0MS,因为数据只有4*4,不过更牛的做法是转为二分图的最大匹配,暂缺。。#include <stdio.h>#include <string.h>#define MAXN 5int n,ans,cnt;char map[MAXN][MAXN];bool isvalid(int x,int y){ map[x][y]='H'; int i,j; bool h=fa... 阅读全文
posted @ 2010-08-24 21:43 菜到不得鸟 阅读(433) 评论(0) 推荐(0)
摘要://16MS#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define MAXN 65bool mycmp(int a,int b){//降序,否则超时 return a>b;}int n,unit,num,sticks[MAXN];bool ok... 阅读全文
posted @ 2010-08-22 20:07 菜到不得鸟 阅读(135) 评论(0) 推荐(0)
摘要://四重循环,32MS#include <stdio.h>#define MAXN 101int main(){ int N,a,b,c,d,sum,pow3[MAXN]; for(int i=1; i<MAXN; i++) pow3[i]=i*i*i; while(scanf("%d",&N)!=EOF) { for(a=6; a<=N; a++) for(b=2... 阅读全文
posted @ 2010-08-21 22:06 菜到不得鸟 阅读(145) 评论(0) 推荐(0)
摘要:传说中的迭代加深算法(ID),第一次认识,其威力真强。融合了普通dfs和普通bfs的优点,于是就可以做出最短加法链此外还有IDA*算法,有待学习啊。。。#include <stdio.h>#define N 101int n,deep,lim,num[N]= {1};bool ok;void dfs(int cur,int d){ if(d > deep) return; if(... 阅读全文
posted @ 2010-08-18 14:26 菜到不得鸟 阅读(147) 评论(0) 推荐(0)
摘要:普通广搜而已,只不过队列是优先队列,以时间为key#include <stdio.h>#include <string.h>#include <queue>using namespace std;#define MAXSIZE 110struct qnode{ int x,y,time; bool operator<(const qnode &e)... 阅读全文
posted @ 2010-08-18 14:00 菜到不得鸟 阅读(136) 评论(0) 推荐(0)
摘要:传说中的奇偶剪枝,但是这题的数据,在dfs前判断一下,可以变得很快。171MS:#include <math.h>#include <iostream>using namespace std;#define MAX 10const int dir[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};int N,M,T,di,dj;char maze[MAX... 阅读全文
posted @ 2010-08-18 13:58 菜到不得鸟 阅读(340) 评论(0) 推荐(0)
摘要://是pku3278 Catch That Cowr的翻版#include <stdio.h>#include <string.h>#define MAXSIZE 210int N,A,B,number[MAXSIZE],queue[MAXSIZE],step[MAXSIZE],front,rear;void bfs(){ while(front<rear) { in... 阅读全文
posted @ 2010-08-18 13:53 菜到不得鸟 阅读(173) 评论(0) 推荐(0)
摘要://普通的广搜#include <stdio.h>#include <string.h>#define QMAX 150000 //因为不是循环队列#define LIM 100001int N,K,front,rear,visited[LIM]= {0},que[QMAX];void bfs(){ front=rear=-1; que[++rear]=N; while( ... 阅读全文
posted @ 2010-08-18 13:51 菜到不得鸟 阅读(178) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>char board[10][10];int n,k,ans,chess;bool r_used[10],c_used[10];void dfs(int row){ if(chess==k) { ans++; return ; } if(n-row < k-chess ) return ; fo... 阅读全文
posted @ 2010-08-18 13:48 菜到不得鸟 阅读(151) 评论(0) 推荐(0)
摘要:全排列问题,too#include <stdio.h>#include <string.h>#define MAX 100int N,sum,a[MAX],myhash[MAX],out[MAX],shot[MAX];bool work;bool calc(){ int i=0,j,lim=N; for(i=0; i<lim; i++) shot[i]=out[i];... 阅读全文
posted @ 2010-08-18 13:47 菜到不得鸟 阅读(168) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#define N 15int t,n,a[N],out[N],o;bool flag,used[N];void dfs(int cur,int sum){ if(sum==t) { flag=false; bool first=true; for(int i=0; i<o; i++) { if... 阅读全文
posted @ 2010-08-18 13:45 菜到不得鸟 阅读(645) 评论(0) 推荐(0)
摘要:又是简单的全排列问题//STL模板#include <stdio.h>#include <algorithm>using namespace std;#define MAX 1005int N,M,a[MAX];int main(void){ while(scanf("%d %d",&N,&M)!=EOF) { int i; for(i=1; i<=N... 阅读全文
posted @ 2010-08-18 13:44 菜到不得鸟 阅读(358) 评论(0) 推荐(0)
摘要:这题和pku1731 Orders差不多。//法1 63MS#include<iostream>#include <algorithm>#include<string>using namespace std;char str[15]; //存储输入字符串char out[15]; //存储输出字符串bool used[15]; //字符是否已经使用int N; ... 阅读全文
posted @ 2010-08-18 13:42 菜到不得鸟 阅读(212) 评论(0) 推荐(0)
摘要:简单的不重复排列问题//法1 让脚标i自加消重复#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>using namespace std;#define MAX 205char str[MAX],out[MAX];int len;bool used[... 阅读全文
posted @ 2010-08-18 13:39 菜到不得鸟 阅读(133) 评论(0) 推荐(0)
摘要://非递归:#include <cstdio>#include <cmath>#include <cstdlib>using namespace std;#define N 22int a[N],x[N],second,tag;const bool isprime[41]= {0, 0,1,1,0,1,0,1,0,0,0, 1,0,1,0,0,0,1,0,1,0... 阅读全文
posted @ 2010-08-18 13:32 菜到不得鸟 阅读(236) 评论(0) 推荐(0)
摘要://1.非递归:#include <cstdio>#include <cmath>using namespace std;#define N 13int x[N];bool isvalid(int k){ int i; for(i=0; i<k; i++) if(x[i]==x[k] || abs(x[i]-x[k])==abs(i-k)) return false;... 阅读全文
posted @ 2010-08-18 13:26 菜到不得鸟 阅读(472) 评论(0) 推荐(0)

1