摘要: 一、核心性质:三角不等式。最短路满足d[v]maxlongint。借此提出:当dis[]>N*MaxEdge,可以判正环。(类比于入队n次) 2、环构成了连通分量,那么缩点后去掉连通分量之间的边,不影响判正(负)环。 3、牺牲程序正确性来判正(负)环。已知SPFA的平均运行时间为O(KM);而在存在环时,会因不断迭代使程序效率低下。借此提出:当程序效率低下时,存在正(负)环。表现形式为所有点入队总次数>T*(M+N),就判定存在,T一般取2,具体根据题目时限修改。分析:事实上,正是因为bfs迭代的不连续性,导致不能直接找到正环,退而求次,以n次入队判定。而n次入队其实包含了大量的冗 阅读全文
posted @ 2013-08-20 20:26 Thousand Sunny 阅读(1811) 评论(1) 推荐(0) 编辑
摘要: 暴力水过,剪一下枝= =果断是数据水了 1 #include 2 #include 3 #include 4 #define LL __int64 5 using namespace std; 6 7 const int MAXN=111111; 8 char str[MAXN]; 9 10 int same(int a,int b,int x,int y)11 {12 if(a==x)13 return min(b,y)-a;14 int i=0;15 while((a+i)<b&&(x+i)<y&&str[a+i]==str[x+i])16 .. 阅读全文
posted @ 2013-08-20 19:06 Thousand Sunny 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 还有什么好说的呢?打表题= = 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 #define MP make_pair 8 9 map ,pair > mm;10 11 void init()12 {13 mm[MP('0','0')] = MP('0','0');mm[MP('0','1')] = MP('0','1');mm[MP('0',' 阅读全文
posted @ 2013-08-20 17:12 Thousand Sunny 阅读(198) 评论(0) 推荐(0) 编辑