摘要: 之前尝试用 Dijkstra 写,但是回溯部分不会写,无奈之下网上找了一下别人的解题报告,发现竟然是用 Floyd 写的,我接触 Floyd 不太深入,于是在做这道题目的时候,我重新回顾了 Floyd 算法,思考其核心思想预处理:约定 edge 保存输入数据的边权值,tax 保存站点的费用,ss,tt 分别记录当前的 起点 和 终点,那么可以这样构图,对于 ss 和 tt,显然这两点是不需要 tax 的,那么dist 数据记录 ss 到 当前点 k 的总费用,即 dist[ i ][ j ] = edge[ i ][ j ] + tax[ j ] (edge[ i ][ j ]!=0,edge 阅读全文
posted @ 2012-08-09 20:51 Maxwell:My Blog 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <memory.h> 6 7 int mat[1010][1010]; 8 int i, nNum, tx, ty, ai, bi; 9 int dx[] = {-1, 1, 0, 0};10 int dy[] = {0, 0, -1, 1};11 12 struct path13 {14 int x, y, step;15 }q[1000010 阅读全文
posted @ 2012-08-09 14:55 Maxwell:My Blog 阅读(327) 评论(0) 推荐(0) 编辑
摘要: 原创转载请注明:www.cnblogs.com/yewei思路:先将所有的单词插入到 Trie 中,然后对于每个单词枚举前后位置 1 /* 2 PROG: Hat’s Words 3 ID : yewei 4 LANG: C++ 5 */ 6 #include <cstdio> 7 #include <cstdlib> 8 #include <cstring> 9 #include <memory.h> 10 11 //const int size = 102; 12 const int maxn = 50004; 13 14 struct Tr 阅读全文
posted @ 2012-08-09 14:54 Maxwell:My Blog 阅读(364) 评论(0) 推荐(0) 编辑
摘要: 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int vis[305][305], mat[305][305]; 5 int dx[] = {-2, -2, -1, 1, 2, 2, 1, -1}; 6 int dy[] = {-1, 1, 2, 2, 1, -1, -2, -2}; 7 int casenum, nNum, sx, sy, tx, ty, i; 8 9 struct point10 {11 int x, y;12 }cur, next, q[90005]={0};13 14 int IsInBound(i 阅读全文
posted @ 2012-08-09 14:52 Maxwell:My Blog 阅读(2039) 评论(0) 推荐(0) 编辑
摘要: 在HDOJ上提交通过以后,再在zoj上提交,结果得到了无数个WA,后来发现有一种情况我并没有考虑到有几个关键的地方需要注意:1. Angel的朋友不只有一个,可能有多个2. guard的存在可能会破坏广度优先树解决办法:BFS的做法:必须要保存guard与可行点‘.’的插入同步,因为guard的costTime不同,应该先不改变其坐标,costTime增加一以后,设为已被访问,‘x’变为‘.’或者‘#’,重新入队,此时,guard已被插入到队列的尾部,这样一来,guard与‘.’就可以同步了View Code 1 #include <math.h> 2 #include <s 阅读全文
posted @ 2012-08-09 14:52 Maxwell:My Blog 阅读(676) 评论(0) 推荐(0) 编辑
摘要: 因为没有对边判重,白白WA了好几次,注意输入时必须要对边判重AC 187MS 8100K 1 #include <queue> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <memory.h> 5 using namespace std; 6 7 const int maxn = 1001; 8 const int INF = 0x3F3F3F3F; 9 10 int a, b, d, p, nNum, mNum;11 int dist[maxn], px[maxn], QM[max 阅读全文
posted @ 2012-08-09 14:50 Maxwell:My Blog 阅读(490) 评论(0) 推荐(0) 编辑
摘要: 原创转载请注明:www.cnblogs.com/yewei方法一:Trie思路:1. 开辟一个结构体数组dict,数组中存放索引值和索引,比如from fiwo2.建立一颗Trie,Trie维护 整型变量 index,结构体指针数组 branch,在建立Trie的过程中,若是单词结尾,Trie中index赋值为dict的索引,否则为-1写法一:string类降低编码复杂度,当然代价是时间复杂度加大约 2 倍View Code 1 /* 2 PROG: What Are You Talking About 3 ID : yewei 4 LANG: C++ 5 */ 6... 阅读全文
posted @ 2012-08-09 14:43 Maxwell:My Blog 阅读(311) 评论(0) 推荐(0) 编辑