随笔分类 -  搜索题

摘要:#include <cstdio>#include <iostream>#include <queue>using namespace std;int dir[8][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{-2,1},{2,-1},{-2,-1}};int vis[9][9];int sx,sy,ex,ey;struct node{ int x,y,step;};int num;queue<node> q; void bfs(int x1,int y1) { int i; while(!q.empty()) 阅读全文
posted @ 2012-06-04 14:04 shijiwomen 阅读(232) 评论(0) 推荐(0)
摘要:#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;int a[1005][1005],vis[1005][1005];int dic[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int n,m;struct node{ int x,y,dir,corner;};node start,end;void bfs(){ queue<node> q; int i; node pre,cur; 阅读全文
posted @ 2012-05-24 21:41 shijiwomen 阅读(184) 评论(0) 推荐(0)
摘要:n个数,+、-、.号等于0的等式 输出等式和总过的等式#include <iostream>#include <cstdio>#include <string.h>using namespace std;const int MAXN=20;const int MAXM=16;char str[MAXM],opt[MAXN][MAXM];int n,cnt;void dfs(int deep,int num,int pre){ int now,k; if(deep==n) { str[n]='\0'; if(num==0) { if(cnt&l 阅读全文
posted @ 2012-04-13 23:28 shijiwomen 阅读(332) 评论(0) 推荐(0)
摘要:一做这题,才感觉我一直没有真正的理解dfs,dfs其实就是一种枚举,一种靠递归,靠剪枝优化的枚举而且能根据具体问题进行剪枝,和递归的条件,看来我还得更深刻地去理解一前的算法,这很重要还有就是vis[]是否访问数组标识,其实就是一个区分,区分成两组,这是实质#include <stdio.h>#include <string.h>#define node 25int dividen[node];int c[node][node];int n,max;void dfs(int num,int t){ int i,data=t; dividen[num]=1; for(i=1 阅读全文
posted @ 2012-04-08 10:58 shijiwomen 阅读(748) 评论(0) 推荐(0)
摘要:递推式的时候一定要注意+号m+=m+n,左边的加号加不加我查了半天啊#include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<queue> #include<set> #include<stack>#include <fstream> using namespace std;#define max 8000003struct node{ char state[3][3]; int x,y; 阅读全文
posted @ 2012-04-01 08:55 shijiwomen 阅读(319) 评论(0) 推荐(0)
摘要:题意:倒水问题,现在有两个容积为a和b的水壶,对每个水壶可以进行4种操作,两个水壶之间相互倒水(一个水壶倒空或者一个水壶倒满为止),从水农头那里灌水(将水壶灌满为止),向外倒水(将水壶倒空为止),问对这两个水壶进行这样的一系列操作是否可以量出容积为c的水(两个杯子中有一个水壶中的水的容积恰好为c) 由于题目是"Special Judge",即答案不是唯一的,题目给出了三项假设: 1> 只有两个水壶 2> 对于每个输入,都有一个确定的输出 3> 0<c[a]<=c[b]和N<=c[b]<=1000 也就是水壶A肯定比水壶B小,水壶B肯 阅读全文
posted @ 2012-03-31 20:13 shijiwomen 阅读(769) 评论(0) 推荐(0)
摘要:主要是剪枝:分为总体和枝节总体:sum%4!=0,max<sum/4枝节:在于dfs的参数设置和条件判断,动态的判断是否进行参考代码(参考牛人的):#include <stdio.h>#include <stdlib.h>#include <string.h>int a[25],vist[25],m,ave,flag;int cmp(const void *a,const void *b){ return (int *)b-(int *)a;}int dfs(int res,int sums,int cur){ int i; if(sums==ave) 阅读全文
posted @ 2012-03-28 21:14 shijiwomen 阅读(2918) 评论(0) 推荐(0)
摘要:思想1:电脑就是一个有特性(很有耐心)的小孩,作为编程人员应该站在它的角度考虑问题,编程就是用一种特定的编程语言跟它交流。思想2:站在编程员得角度思考,数学是电脑的神经,数学思维是他的灵魂,数学知识是他的身体,知识是有体系的,他有自己独有的性质、属性、规律,编程人员就是用一种特定的编程语言依据他独有的知识、属性、规律进行有规律的不断的推理,直到到达目标,而这目标和知识以及他的一些性质都是由现实生活中一些实际问题,经过分块简化抽象,数学模型抽象而来。算法核心:回溯在现实生活中就是一种试探的尝试,例如,你很久以前去过一个地方,只很清楚记得目的地的一个特征(假设到时你能知道),现在你在一个十字路口, 阅读全文
posted @ 2011-03-26 18:26 shijiwomen 阅读(923) 评论(0) 推荐(0)