上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 28 下一页
摘要: 思路:对每一条边涂上颜色1或-1,颜色值加到关联的两个点上,则一种成功的方案必须满足最后每个点的值为0.剪枝:统计出和某个点i相关联的边的个数,如果枚举到某一条边的时候发现:abs(sum[i]) > degree[i],则剪去,其中sun[i]表示i点的值,degree[i]表示剩下的还没有枚举的... 阅读全文
posted @ 2015-07-23 20:48 hxy_has_been_used 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 这道题中,边权属于[0,1],并且多段路的长度为各段的乘积。联系dijstra算法的特点,我们可以采取类似于dijstra的贪心策略,每次选取到源点距离最大的点,因为现在源点到其他的点的距离都不大于这个距离,以后如果再加上某一段,总的长度便会乘上一个不大于1的数字,就更不可能比现在选取的这个距离大了... 阅读全文
posted @ 2015-07-23 20:32 hxy_has_been_used 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 认识的人之间建立一条权值为1的边,然后求出各对顶点之间的最短路判断是否有长度大于7的。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF = 999999; 8 cons... 阅读全文
posted @ 2015-07-23 19:56 hxy_has_been_used 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 这个题的置换恰好是有规律的,所以也不用把置换给存下来,然后只要求出置换的循环节就可以了。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int N = 200001; 8 bool ... 阅读全文
posted @ 2015-07-23 19:00 hxy_has_been_used 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 建立一个超级源点0和超级汇点n,求0到n的最短路就行了。dijstra: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF = 9999999; 8 const int ... 阅读全文
posted @ 2015-07-23 09:23 hxy_has_been_used 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 题意:求离一个城市第k远的城市的编号,无负权边。思路:根据dijstra算法的特点可以知道,外层循环n次,每次求出的点就是离源点第i远的点的最短路。所以迭代k次,第k次新求出的点即为答案。 1 #include 2 #include 3 #include 4 #include 5 using... 阅读全文
posted @ 2015-07-22 15:19 hxy_has_been_used 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 求最小费用最短路:即在路径长度尽量小的情况下使得花费尽量小。其实就是在松弛多了一种情况就是:路径长度相等但费用小。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF = ... 阅读全文
posted @ 2015-07-22 12:57 hxy_has_been_used 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 先求一遍最短路,然后判断哪条路可以走再记忆化搜索统计方法数。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF = 99999999; 8 const int N = 1... 阅读全文
posted @ 2015-07-22 12:36 hxy_has_been_used 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 需要注意的是这个题不仅有边权还有点权,起点和终点的点权不算。思路还是一样,只是把路过的点的点权也加上再松弛即可。另外,距离相等的时候需要判断一下,选择字典序小的链连到这个点,方法就是把这个点以及之前的点放到栈里比较。 1 #include 2 #include 3 #include 4... 阅读全文
posted @ 2015-07-22 11:53 hxy_has_been_used 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 最大伪森林:原图的一个子图,在子图的各个连通分量中至多有一个环,且各边权和最大。方法:kruskal,只是排序按边权从大到小,合并的时候注意判断是否构成多个环。 1 #include 2 #include 3 #include 4 #include 5 using namespace std... 阅读全文
posted @ 2015-07-20 15:32 hxy_has_been_used 阅读(175) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 28 下一页