随笔分类 -  拓扑排序

poj 1094 拓扑排序
摘要:悲剧,这题错得好惨,首先这题题意就没仔细看清,误读题意。读懂题意后又悲剧了,当不确定时还要判断是否有回路。判断回路时又用了错误算法,思考不认真,当然知道可以用Floyd传递闭包判断就是没用。自以为题目不会那么麻烦,直接判断入度就可以了。自己得想法真的太二。怎么可以用判断入度就可以判断有无回路呢?正确算法:1.边输入边(A《B)就要边处理。先判断是否有冲突,然后判断是否不确定。确定冲突或答案后只要把后面得数据读进来就可以,不用处理。2.拓扑排序算法3.Floyd判断是否有回路View Code #include<stdio.h>#include<stdlib.h>#inc 阅读全文

posted @ 2012-07-13 11:54 more think, more gains 阅读(264) 评论(0) 推荐(0)

产生冠军
摘要:这题处理下字符串,判断下入度为零的点就可以了。。#include <stdio.h>#include <string.h>#include <stdlib.h>char name[2011][100];char str1[100],str2[100];//int map[2021][2211];int dp[2022];int N, M, flag;int find( char *s ,int x){ int i; for ( i = 0; i < x; i++) if(strcmp(s,name[i]) == 0) return i; return 阅读全文

posted @ 2011-07-20 11:04 more think, more gains 阅读(201) 评论(0) 推荐(0)

确定比赛名次 最简单的拓朴排序
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <stack>using namespace std;int N, M, dp[510], visit[510];int map[510][510]; int main( ){ int i, j, a, b, t, flag, k; while (scanf("%d%d", &N, &M) != EOF) { flag = 0; k = 0; stack<int>q; m 阅读全文

posted @ 2011-07-20 11:00 more think, more gains 阅读(260) 评论(0) 推荐(0)

reward
摘要:关键点是每一次点度数减1后,要即时更新其奖金值。。 用邻接矩阵写超时,学了下用STL vector写邻接表。用stl真的非常方便但是非常要时间啊 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <vector> 5 #include <stack> 6 7 using namespace std; 8 9 int N, M, i, j ,t1, t2, sum ,l, a, b;10 int dp[10010],exp[10010] 阅读全文

posted @ 2011-07-20 10:59 more think, more gains 阅读(243) 评论(0) 推荐(0)

Legal or Not
摘要://用邻接矩阵写的,加 stl 栈,自己写栈也好简单的,直接开个数组,一个指针就可以了。。用stl太废时间了。//有些题目很容易超时 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <stack> 5 using namespace std; 6 7 int N, M, dp[110], visit[510]; 8 9 int map[110][110];10 11 int main( )12 {13 int i, j, a, b, t, fl 阅读全文

posted @ 2011-07-20 10:55 more think, more gains 阅读(227) 评论(0) 推荐(0)

导航