随笔分类 - bfs/gfs
摘要:早就感觉这一题很有意思,一直迫于麻烦没有写,今天下午花了将近三个小时AC掉了,呵呵,以后就不怕这样的数独了。大致思路:用一个结构体s,将每一个‘?’的位置信息记录,以备后面DFS。对s中的每一个元素进行遍历,即对每一个‘?’号遍历。每个‘?’号处试着放入1-9的数并检查这个数是否符合要求。即,检查一行,一列以及一个3×3方格内是否有相同的数。刚开始,每组个实例后输出一个空格后说是表达错误,应该是最后一组实例多输入空格了吧! 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 u
阅读全文
摘要:纠结了一个上午,原来是运算符重载弄错了!我去。该题用一个四维数组标记人和箱子的当前状态。在判断是否满足队列条件时,用continue巧妙的处理了,如果搬运工遇到箱子的问题。 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<queue> 5 using namespace std; 6 struct node 7 { 8 int x,y; 9 int bx,by; 10 int step; 11 bool friend operator<(node
阅读全文
摘要:Problem DescriptionNow give you an string which only contains 0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9.You are asked to add the sign ‘+’ or ’-’ between the characters. Just like give you a string “12345”, you can work out a string “123+4-5”. Now give you an integer N, please tell me how many ways can you find t
阅读全文
摘要:Problem link adress:http://acm.hdu.edu.cn/showproblem.php?pid=1026这个题目很早就见了,只是碍于没有打印BFS路径的经验就放到了今天!下面先写一种用记录前驱路径的打印方法。本文仅描述打印路径的部分,BFS就略了。实现过程:从出口向入口进行搜索,并记录下每个位置的前一个位置信息(即把当前的位置和前一个位置联系起来),这样就穿成了一条从头到尾的路径。比如 从1搜到10,我们可以考虑从10搜到1,当搜索到9的时候,记录下9的前一个位置即10,这样依次向前直到1;然后输出的时候就可以先输出1,然后输出1的前一个标记点即2,然后输出2的前一
阅读全文
摘要:hdu 2425 Hiking Trip Problem link adress:http://acm.hdu.edu.cn/showproblem.php?pid=2425A simple bfs problem!Notice: If " There is a blank line after each test case." appeared in the INPUT format, we needn't output one blank more after each test case;View Code 1 #include<iostream>
阅读全文
摘要:Problem link adress:http://acm.hdu.edu.cn/showproblem.php?pid=1241These days I have encountered some problems when I was doing the searching problems;May those problem need to use the DFS algorithm! So I started to learning the DFS:Lots of friends saysthis probelm is a simple DFS problem, so I have
阅读全文
摘要:Problem link adress:http://acm.hdu.edu.cn/showproblem.php?pid=2645//*****analysis*****//The meaning of the problem is simple.In the map consist of '0' and '1',find the nearest '1' for every '0'.Clearly, we should use bfs work out every nearest station.Is it brute forc
阅读全文