随笔分类 -  拓扑排序

摘要://题目类型:拓扑排序//解题思路:利用拓扑排序,如果在一次排序中,所有点的入度均不为0,则判断存在环,即非法。 #include <iostream>//#include <conio.h>using namespace std;#define narray 101int graph[narray][narray];int indegree[narray];int n,m... 阅读全文
posted @ 2010-06-09 17:13 北海小龙 阅读(367) 评论(0) 推荐(0)
摘要:int graph[narray][narray]; //邻接阵 int indegree[narray]; //记录顶点的入度 int n; //n为顶点个数 memset(graph,0,sizeof(graph));memset(indegree,0,sizeof(indegree));for(i=1;i<=n;++i) //遍历n次每次找出一个顶点 { for(j=1;j<=n... 阅读全文
posted @ 2010-06-09 16:42 北海小龙 阅读(284) 评论(0) 推荐(0)
摘要://拓扑排序的经典题目//此题切忌:无法排序的情况下也可能出现环的情况#include <iostream>#include <string>using namespace std;#define arraysize 30int map[arraysize][arraysize];//存储邻接阵int indegree[arraysize];//存储节点入度char res... 阅读全文
posted @ 2010-05-21 11:36 北海小龙 阅读(287) 评论(0) 推荐(0)
摘要://贪心看完后在看看此题//题目分类:拓扑排序+贪心拓扑排序参考:(1)http://www.answeror.com/archives/23913(2)http://hi.baidu.com/lewutian/blog/item/90803c6ed2afe7d181cb4aa8.html/cmtid/5c9feacbc9f19c12bf09e67f总结:(1)题目大意:有N个小球,重量从小大排列... 阅读全文
posted @ 2010-05-21 11:36 北海小龙 阅读(682) 评论(0) 推荐(1)
摘要://典型的拓扑排序算法(邻接阵形式),可以作为拓扑排序的模板 #include <iostream>//#include <conio.h>using namespace std;#define arraysize 501int map[arraysize][arraysize]; //存储图的临界阵 int n,m;int indegree[arraysize]; //存... 阅读全文
posted @ 2010-05-21 11:35 北海小龙 阅读(685) 评论(0) 推荐(0)