随笔分类 - 广度搜索
摘要:题意:有两个杯子 容量分别为 A,B;每次可以将其中一杯杯子倒满或倒空,或者将一个杯子中的水倒入另外一个杯子(必须将其中一个杯子倒空或倒满)。 这样每种状态就有可能衍生出六种新的状态。 典型的BFS。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 int n,m; 11 12 bool sta[110][110]; 13 14 struct Q 15 { 16 int n,m,step,mar...
阅读全文
摘要:简单的BFS + 素数筛。。。。。手残把素数筛敲错了 调试了大半年......不过终于迎来了久违的 1A 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 bool HashPrime[10010]; 11 bool Mark[10010]; 12 13 struct N 14 { 15 int p,s; 16 }t,nt; 17 18 void bfs(int n,int m) 19 { 20 ...
阅读全文
摘要:毫无意义的三维BFS..... 从 S 出发 每次可以选择六个方向 求到 E 的最小移动次数 。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 char maze[31][31][31]; 11 bool MarkMaze[31][31][31]; 12 13 struct P 14 { 15 int l,r,c,step; 16 }sp,ep,tp,np; 17 18 int L,R,C,le...
阅读全文
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 char a[6][6]; 5 int v[6][6],hash[6][6];//V标记是否已经放过,hash标记是否此位置是否进入过队列 6 int n,sum,max; 7 8 struct N 9 {10 int x,y;11 };12 13 14 int judge(int x,int y)15 {16 int i,j;17 for(i = x+1; i <= n; i++)18 if(v[i][y]) return 0;19 else...
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int n,h[1010]; 6 7 struct M 8 { 9 int data;10 struct M *next;11 }*head[1010];12 13 struct Q14 {15 int step;16 int site;17 };18 19 void init()20 {21 int i;22 for(i = 1;i <= n; i++)23 {24 head[i] =...
阅读全文
摘要:#include<stdio.h>#include<string.h>int mark,k,m,map[101][101],vis[101][101],h[105];void seek(int mb){ int q[100],i,s,e; s = e =0; q[e++] = mb; while(s < e) { mb = q[s++]; if(mark) { mark = 0; printf("%d",mb); } else printf(" %d"...
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>int k,h[110],mark;struct M{ int data; struct M *next;}*head[110];void init(){ int i; for(i = 0; i < k; i++) { head[i] = (struct M *)malloc(sizeof(struct M)); head[i]->next = NULL; head[i]->data = -1; }}void l...
阅读全文
摘要:#include<string.h>#include<stdio.h>int a,b,c,pos[52][52][52];struct POS{ int x,y,z;} q[125110];int bfs(){ int s,e,i; struct POS temp,t; int jx[] = {0,0,0,0,1,-1}; int jy[] = {0,0,-1,1,0,0}; int jz[] = {-1,1,0,0,0,0}; s = e = 0; q[e].x = q[e].y = q[e].z = 0; e++; while(s...
阅读全文
浙公网安备 33010602011771号