随笔分类 -  BFS&DFS

1
Super Phyllis(穷举+搜索)
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2723题意:给出一些字符串u,v,代表u->v,问有几条边是多余的,也就是说去掉那些边后,u仍能到达v。思路:穷举每条边,试着去掉该边,bfs搜索两个点是否仍然可达。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 char s1[210],s2[210],.. 阅读全文
posted @ 2013-12-02 15:09 straw_berry 阅读(369) 评论(0) 推荐(0)
Rocky(dfs)
摘要:题目描述Sylvester Stallion is an old horse who likes nothing better than to wander around in the fields around his stable. Sylvester is a little single minded and will walk in a straight line unless there is a rock in this path. If that\'s the case, he does one of three things: 1) if there is no roc 阅读全文
posted @ 2013-12-02 10:32 straw_berry 阅读(322) 评论(0) 推荐(0)
Eight(bfs+全排列的哈希函数)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:22207Accepted:9846Special JudgeDescriptionThe 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all pa 阅读全文
posted @ 2013-10-22 20:36 straw_berry 阅读(517) 评论(0) 推荐(0)
Shredding Company(dfs)
摘要:Time Limit:1000MSMemory Limit:10000KTotal Submissions:3519Accepted:2009DescriptionYou have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shred sheets of paper into little pieces so that the contents would become unrea 阅读全文
posted @ 2013-08-22 20:54 straw_berry 阅读(249) 评论(0) 推荐(0)
Curling 2.0(dfs)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:8795Accepted:3692DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only 阅读全文
posted @ 2013-08-22 10:59 straw_berry 阅读(222) 评论(0) 推荐(0)
Channel Allocation(四色定理 dfs)
摘要:Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 10897Accepted: 5594DescriptionWhen a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully ch 阅读全文
posted @ 2013-08-21 23:11 straw_berry 阅读(319) 评论(0) 推荐(0)
Sudoku(回溯)
摘要:Time Limit:2000MSMemory Limit:65536KTotal Submissions:12075Accepted:6026Special JudgeDescriptionSudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The other ce 阅读全文
posted @ 2013-08-21 16:45 straw_berry 阅读(199) 评论(0) 推荐(0)
Pots(bfs)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:8266Accepted:3507Special JudgeDescriptionYou are given two pots, having the volume ofAandBliters respectively. The following operations can be performed:FILL(i) fill the poti(1 ≤i≤ 2) from the tap;DROP(i) empty the potito the drain;POUR(i,j) pour 阅读全文
posted @ 2013-08-20 20:39 straw_berry 阅读(273) 评论(0) 推荐(0)
Prime Path(素数筛选+bfs)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:9519Accepted:5458DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of security to change suc 阅读全文
posted @ 2013-08-20 10:29 straw_berry 阅读(270) 评论(0) 推荐(0)
A Knight's Journey(dfs)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:25950Accepted:8853DescriptionBackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the world. Whenever a knight moves, it is two squares in one direction and one s 阅读全文
posted @ 2013-08-19 20:27 straw_berry 阅读(262) 评论(0) 推荐(0)
Finding Nemo(bfs)
摘要:Time Limit:2000MSMemory Limit:30000KTotal Submissions:6988Accepted:1600DescriptionNemo is a naughty boy. One day he went into the deep sea all by himself. Unfortunately, he became lost and couldn't find his way home. Therefore, he sent a signal to his father, Marlin, to ask for help.After checki 阅读全文
posted @ 2013-08-13 14:17 straw_berry 阅读(324) 评论(0) 推荐(0)
Children of the Candy Corn (bfs+dfs)
摘要:Time Limit:1000MSMemory Limit:65536KTotal Submissions:8120Accepted:3547DescriptionThe cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exi 阅读全文
posted @ 2013-08-07 10:37 straw_berry 阅读(210) 评论(0) 推荐(1)
棋盘问题
摘要:Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n 3 #include 4 using namespace std; 5 6 int n,k,ans; 7 char map[10][10]; 8 int vis[10];//标记某列是否被访问 9 10 void dfs(i.. 阅读全文
posted @ 2013-07-30 08:26 straw_berry 阅读(328) 评论(0) 推荐(0)
Catch That Cow
摘要:题目描述Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleportin 阅读全文
posted @ 2013-07-15 18:34 straw_berry 阅读(204) 评论(0) 推荐(0)
走迷宫
摘要:题目描述一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方向任意走一步,并且有些格子是不能走动,求从起点到终点经过每个格子至多一次的走法数。输入 第一行一个整数T 表示有T 组测试数据。(T 2 #include 3 int map[101][101],vis[101][101]; 4 int n,m,ans; 5 void dfs(int x,int y) 6 { 7 if(vis[x][y] || map[x][y]) 8 return; 9 if(x == n && y == m)10 {1... 阅读全文
posted @ 2013-06-24 00:49 straw_berry 阅读(259) 评论(0) 推荐(0)
Balloons dfs
摘要:Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.They were very interested about this event, and also curious about the image.Since there are too many balloons, it is very hard for them to compute an 阅读全文
posted @ 2013-05-18 16:17 straw_berry 阅读(231) 评论(0) 推荐(0)
邻接矩阵的宽度遍历
摘要:sdut 2141 1 #include 2 #include 3 int mapp[110][110],vis[110],que[110],flag; 4 int k,m,t; 5 void bfs(int t) 6 { 7 int l=0,r=0,tt,j; 8 que[r++]=t; 9 while(l<r) 10 { 11 tt=que[l++]; 12 if(flag==1) 13 { 14 flag=0; ... 阅读全文
posted @ 2013-03-30 21:50 straw_berry 阅读(211) 评论(0) 推荐(0)
邻接矩阵的深度遍历
摘要:sdut 2107 图的深度遍历 1 #include 2 #include 3 int map[110][110], vis[110]; 4 int m, n, flag; 5 void dfs (int i) 6 { 7 int j ; 8 vis[i] = 1; 9 if( flag == 1)10 {11 printf("%d",i);12 flag = 0;13 }14 else printf(" %d",i);15 for( j=0; j<n; j++ )16 {... 阅读全文
posted @ 2013-03-30 21:38 straw_berry 阅读(275) 评论(0) 推荐(0)
走迷宫 dfs
摘要:走迷宫Time Limit: 1000MS Memory limit: 65536K题目描述一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方向任意走一步,并且有些格子是不能走动,求从起点到终点经过每个格子至多一次的走法数。输入 第一行一个整数T 表示有T 组测试数据。(T 2 #include 3 int count=0; 4 int vis[100][100], map[100][100]; 5 int n,m; 6 void dfs(int i,int j) 7 { 8 if(vi... 阅读全文
posted @ 2013-03-23 19:09 straw_berry 阅读(252) 评论(0) 推荐(0)
基于邻接矩阵的广度优先搜索遍历
摘要:数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历Time Limit: 1000MS Memory limit: 65536K题目描述给定一个无向连通图,顶点编号从0到n-1,用广度优先搜索(BFS)遍历,输出从某个顶点出发的遍历序列。(同一个结点的同层邻接点,节点编号小的优先遍历)输入输入第一行为整数n(0#includeint map[110][110], vis[110],que[110];int k,m,t,flag,tt;void bfs(int t){ int l=0,r=0,j; que[r++]=t; while(l<r) { tt=qu... 阅读全文
posted @ 2013-03-14 21:27 straw_berry 阅读(363) 评论(0) 推荐(0)

1