上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 99 下一页

2012年7月10日

SPFA

摘要: SPFA与dijkstra算法的区别1. dijkstra算法是含贪心思想,SPFA更像BFS2.BFS每个点只入对一次,而SPFA一个点在出了队列之后,可能会重新入队,在本身改进后,用来改进其他点。3.SPFA可以处理负权边,每个点入队次数超过N,则存在负权环代码:View Code //邻接表存储图的最短路 #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <queue>using namespace std;#d 阅读全文

posted @ 2012-07-10 09:31 more think, more gains 阅读(192) 评论(0) 推荐(0) 编辑

最短路

摘要: 复习下图论算法1. 邻接表的DijkstraView Code //邻接表存储图的最短路 #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>using namespace std;#define MAXN 100100struct Edge{ int u, next, val; Edge() {} Edge( int v , int Next ,int Val): u(v),next(Next), val(Val) { } }edge[MAXN]; 阅读全文

posted @ 2012-07-10 09:08 more think, more gains 阅读(173) 评论(0) 推荐(0) 编辑

2012年7月9日

POJ 2632 模拟题

摘要: 模拟题,不是很恶心。算法:1.写好各种操作函数Turn_Left, Turn_Right, Forward2.处理好各种细节,我wa,主要是由机器编号求其坐标时搞错,还有Turn是没有注意次数。View Code #include<iostream>#include<string.h>#include<stdlib.h>#include<stdio.h>using namespace std;int T, A, B, N, M, maxn;int mp[110][110]; //存储机器人位置,值0表示该坐标无机器人,1表示方向E,2表示S,3表 阅读全文

posted @ 2012-07-09 21:25 more think, more gains 阅读(167) 评论(0) 推荐(0) 编辑

poj 1068 模拟题

摘要: 模拟题:算法1.由输入的P-sequence构找S2.根据S求每个右括号的左匹配括号,pipei[right] = left3.根据W-sequence定义求结果View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <stack>using namespace std;int p[10000], N;char stk[100000];int pipei[10000];int pre( ){ int x 阅读全文

posted @ 2012-07-09 16:57 more think, more gains 阅读(126) 评论(0) 推荐(0) 编辑

POJ 1328 贪心

摘要: 算法:1.求出覆盖该岛的圆得区间, 將问题转换为求过出最少得点,保证每个区间至少有一个点。2.按区间的左端排序3.更新radView Code #include <stdio.h>#include <iostream>#include <stdlib.h>#include <string.h>#include <algorithm>#include <math.h>using namespace std;struct node{ double x, y; bool operator < (const node& 阅读全文

posted @ 2012-07-09 10:36 more think, more gains 阅读(139) 评论(0) 推荐(0) 编辑

上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 99 下一页

导航