随笔分类 - 差分约束
hdu 3666 THE MATRIX PROBLEM
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3666差分约束,关键在于找不等式,然后建图这个题 spfa 判断负环时,如果以更新次数大于等于N判断有负环,会超时只要判断更新次数大于sqrt(N)就可以,原理不知道代码:#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<set>#include<map>#include<cmath>#include<algorithm
阅读全文
poj 1364 King hdu 1531 King
摘要:http://poj.org/problem?id=1364http://acm.hdu.edu.cn/showproblem.php?pid=1531差分约束 基本上就是 给你数列之间的一些大小限制把它们 转化为点之间的限制条件 限制条件代表边就变成最短路或最长路了 求的时候需判断有没有负环或正环一般用 Bellmen_ford 写 还有就是效率更高一些的 SPFA本题解释见代码注释#include<iostream>#include<cstdio>#include<string>#include<queue>#include<stack
阅读全文
poj 3159 Candies
摘要:http://poj.org/problem?id=3159经过我不断的尝试 老天重要显灵了终于来个个 1400+ms 伤不起呀用 queue 过不了 得用 stack可能对于后台数据 queue 会有一些多余的搜索也可能时 stack 本身比 queue 用快一些anyway 我的代码就得用 stack还有就是题目描述有点问题它是让我们求 flymouse 最多比 snoopy 多得多少 candy#include<iostream>#include<cstdio>#include<string>#include<queue>#include&
阅读全文
poj 2983 Is the Information Reliable
摘要:http://poj.org/problem?id=2983假设以最北为超级源点对于 P north south x 代表south 在 north 的南边 x 光年处则 north 在south 南边的 -x 光年处如果矛盾的话 则及存在负环 也存在正环 我们把-x 这种情况也保存 是为了下面V north south 它是至少 1 光年 如果它使问题矛盾的话 则可利用上面保存的 -x 的情况让我们发现正环所以综合以上 :P 情况 x 和-x 情况都保存,v 只保存 x=1然后用Bellman-Ford 查找是否有正环即可代码如下#include<iostream>#includ
阅读全文
poj 1201 Intervals
摘要:http://poj.org/problem?id=1201第一次做差分约束 看了别人的解析 挺详细的出自http://user.qzone.qq.com/289065406/blog/1307063918然后自己根据自己的理解 写了代码 建议去看上面链接处的解析 非常不错#include<iostream>#include<cmath>#include<string>#include<algorithm>#include<queue>#include<cstring>#include<cstdio>using
阅读全文
浙公网安备 33010602011771号