随笔分类 -  拓扑排序

摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1811 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N=200010; 7 vectorV[N]; 8 queueq; 9 char oper[N];10 int in[N],f[N];11 int a[N],b[N];12 int n,m,sum;13 void init()14 {15 sum = n;16 while(!q.empty()) q.pop();17 ... 阅读全文
posted @ 2014-02-28 14:04 N_ll 阅读(198) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2647#include #include #include #define LL long longusing namespace std;int head[10006],cnt=0;int val[10006];int in[10006];int n,m,num;queueq;struct node{ int u,v; int next;} edge[20010];void add(int u,int v){ edge[cnt].u = u; edge[cnt].v = v; ... 阅读全文
posted @ 2014-02-27 14:55 N_ll 阅读(199) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2094 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=1010; 6 int num = 0,in[N]; 7 string name[N]; 8 int get_nameid(string s) 9 {10 int i;11 for (i = 0; i = num)15 name[num++] = s;16 return i;17 }18 int main()19 {2... 阅读全文
posted @ 2014-02-27 14:52 N_ll 阅读(279) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1285 1 #include 2 #include 3 const int N=1001; 4 int p[N][N],in[N]; 5 int n,m; 6 void toposort() 7 { 8 for (int i = 1; i <= n; i++) 9 {10 for (int j = 1; j <= n; j++)11 {12 if(in[j]==0)13 {14 ... 阅读全文
posted @ 2014-02-27 14:49 N_ll 阅读(169) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1778题意:有两个DVD,第一个DVD上有编号为1~n1的安装包,第二个DVD上有编号为n1+1~n1+n2的安装包,给出m组关系(a,b) 表示安装a之前必须先安装b。由于安装时每次只能插入一个DVD,问安装完所有的安装包,这两个DVD至少要交换插入多少次。ps:第一次插入算一次,最后一次拔出算一次。思路:两次拓扑排序,以先插入第一个DVD,进行拓扑排序,求出交换次数;以先插入第二个DVD,进行拓扑排序,求出交换次数。最后输出这两种交换次数的最小的值。 1 #include 2 #include 3 #include 4 using... 阅读全文
posted @ 2014-02-22 15:55 N_ll 阅读(379) 评论(0) 推荐(0)