图的遍历指的是从图中的任一顶点出发,对图中的所有顶点访问一次且只访问一次。图的遍历操作和树的遍历操作功能相似。图的遍历是图的一种基本操作,图的许多其它操作都是建立在遍历操作的基础之上。图的遍历方法目前有深度优先搜索法和广度(宽度)优先搜索法两种算法。深度优先搜索法DFS深度优先搜索法的基本思想是:从...
分类:
其他好文 时间:
2014-06-27 22:09:35
阅读次数:
310
3D dungeon
时间限制:1000 ms | 内存限制:65535 KB
难度:2
描述You 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 fil...
分类:
其他好文 时间:
2014-06-22 22:13:18
阅读次数:
223
深度优先算法
问题
给定一个有向图,判断其顶点能否到达另外一个顶点。
解决办法
使用深度优先算法,和无向图中的是一样的。
代码
import java.util.Stack;
/**
* Created by caipeichao on 14-6-11.
*/
public class Digrap...
分类:
其他好文 时间:
2014-06-22 21:32:28
阅读次数:
250
spiral grid
时间限制:2000 ms | 内存限制:65535 KB
难度:4
描述Xiaod has recently discovered the grid named "spiral grid".
Construct the grid like the following figure. (The grid is actually infinite...
分类:
其他好文 时间:
2014-06-22 20:54:07
阅读次数:
185
在一个软件工程项目中,有些任务需要在另外一个任务完成之后才能完成,这种任务在软件工程中是非常常见的。下图就展示了一个软件项目的依赖情况。
这张图非常明显,就是一张有向图。那么,现在问题就来了,如何输出任务的完成顺序呢?
这个问题有一个前提条件,就是有向图中不能出现回路。
算法的基本思想就是在每次dfs返回时将顶点加入到返回结...
分类:
其他好文 时间:
2014-06-22 20:03:38
阅读次数:
221
The partial sum problem
时间限制:1000 ms | 内存限制:65535 KB
难度:2
描述One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N ...
分类:
其他好文 时间:
2014-06-22 18:00:48
阅读次数:
166
有向图和无向图在编程中的表示方法是差不多的,本问介绍邻接表表示方法。
有向图对象的代码轮廓如下:
public class Digraph {
public Digraph(int v) {
}
// 创建v到w的边
public void addEdge(int v, int w) {
}
// 获取v能直接到达...
分类:
其他好文 时间:
2014-06-22 13:57:37
阅读次数:
238
用tarjan进行缩点。
然后用dfs求最长路。水体。。。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define maxn 110000
vectorold[maxn];
vectorvec[maxn];
int dnf[maxn],low[maxn],instac...
分类:
其他好文 时间:
2014-06-22 11:51:01
阅读次数:
203
blockhouses
时间限制:1000 ms | 内存限制:65535 KB
难度:3
描述Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing ...
分类:
其他好文 时间:
2014-06-21 22:36:56
阅读次数:
316
胜利大逃亡
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24608 Accepted Submission(s): 9427
Problem Description
Ignatius被魔王抓走了,有一天魔...
分类:
其他好文 时间:
2014-06-21 22:23:25
阅读次数:
317