摘要:在网上看到了一个记录BFS最短路径的方法,个人觉得相当的牛B,所以就将它记录下来了。题目:http://acm.hdu.edu.cn/showproblem.php?pid=1026这个题目比较简单,就不说题意了。直接上代码:View Code #include "iostream"#include "cstring"#include "cstdio"#include "algorithm"#include "queue"using namespace std;#define MAX 10000
阅读全文
摘要:其实说白了,拓扑排序就是一个广度优先搜索。拓扑排序的方法如下: (1)从有向图中选择一个没有前驱(即入度为0)的顶点并且输出它. (2)从网中删去该顶点,并且删去从该顶点发出的全部有向边. (3)重复上述两步,直到剩余的网中不再存在没有前趋的顶点为止.本题目是采用的邻接表存储方法。具体的实现是用vector数组。题目:HDU 1285http://acm.hdu.edu.cn/showproblem.php?pid=1285View Code #include "iostream"#include "vector"#include "queue
阅读全文
摘要:题目:http://acm.swust.edu.cn/oj/problem/4/这是一道简单的题目,但是可以说明问题了。View Code #include "iostream"#include "string"#include "cstdio"#include "cstring"#include "algorithm"#include "queue"using namespace std;char Map[105][105];int Used[105][105];int D
阅读全文
摘要:DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid
阅读全文
摘要:DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure
阅读全文