05 2014 档案
POJ 3669 Meteor Shower
摘要:BFS。 这题是个坑。很久没刷题了,偏偏又遇上这个坑题。下面是坑点: 数据范围是400 400,而不是题目所写的300 300,否则会WA。坑不?我WA了3次才发现。 由于输入巨大,一定要用scanf,而不能用cin,否则会超时。这个是我忘了,不能算题目坑。#include#include... 阅读全文
posted @ 2014-05-24 23:49 xlert 阅读(140) 评论(0) 推荐(0)
POJ 3225 Roadblocks
摘要:贴一道利用优先队列实现的Dijkstra算法。这道题是要求次短路,所以对Dijkstra算法略作修改,同时保存最短和次短路数组。#include#include#include#include#include//#includeusing namespace std; struct Edge{ ... 阅读全文
posted @ 2014-05-24 23:41 xlert 阅读(99) 评论(0) 推荐(0)
POJ 3723 Conscription 并查集 + Kruskal
摘要:#include#include#includeusing namespace std;#define MAX_N 20002#define MAX_E 50001struct edge{ int u, v, cost;};int par[MAX_N];int Rank[MAX_N];edge es... 阅读全文
posted @ 2014-05-24 23:37 xlert 阅读(141) 评论(0) 推荐(0)
C++实现的快速排序
摘要:快速排序,Quick Sort。采用了经典的分治思想:每次确定一个元素的位置,并将序列分为两个子序列:小于等于该元素、大于等于该元素。问题转为分别对刚得到的两个序列进行处理,直到序列长度为1.Partition函数是比较重要的,这里采用了和算法导论类似的想法:每次随机从中抽取一个元素A,将其与序列尾... 阅读全文
posted @ 2014-05-14 23:58 xlert 阅读(203) 评论(0) 推荐(0)
C++实现的一段希尔排序代码
摘要:#include#include#includeusing namespace std;void ShellSort(int *a, int n){ int d; d = n / 2; while (d >= 1) { for (int i = 0; i k; p -= d) { ... 阅读全文
posted @ 2014-05-13 23:19 xlert 阅读(247) 评论(0) 推荐(0)