数据结构
xiaofengsheng
这个作者很懒,什么都没留下…
展开
-
pku 1363 车站
#include using namespace std;#define MAX 1005int map[MAX];int result[MAX];struct Stack{ int stack[MAX]; int index; Stack():index(0) {} void push(int& v) { stack[index++] = v原创 2009-03-12 22:14:00 · 892 阅读 · 0 评论 -
pku 2513 Colored Sticks 欧拉通路问题
这题的本质是欧拉通路的思想.不过还需要并查集来判断是否是联通图, 用trie存储所有的字符串. #include using namespace std;#define swap(i,j) {int temp=i; i = j; j = temp;}struct Node{ int index; Node* arr[26]; Node() { in原创 2010-04-04 17:57:00 · 548 阅读 · 0 评论 -
[标程]: 二叉搜索树和平衡二叉搜索树
贴一个二叉搜索树(BST)和平衡二叉搜索树的标程(BBST). #include #include using namespace std;/************************************************************************//*二叉搜索树标程原创 2010-03-29 22:44:00 · 685 阅读 · 0 评论 -
Heap 自己写的堆的标程
#include using namespace std;inline void _swap(int& a, int& b){ int temp = a; a = b; b = temp;}void heap_adjust(int* arr, int _begin, int _end){ int temp = arr[_begin]; int i原创 2009-12-15 00:07:00 · 563 阅读 · 0 评论 -
pku 1094 Sorting It All Out 拓扑排序
#include #include using namespace std;int edge[27][27]; //图的邻接矩阵int in_degree[27]; //顶点的入度bool flagDegree[27];char strRet[27];int n, m;//拓扑排序//-1: 继续//0: 完成排序//1: 有回路int Topo原创 2009-12-05 09:28:00 · 670 阅读 · 1 评论 -
pku 1634 Who's the boss? stl排序+二分查找
#include #include #include using namespace std;struct Person{ int id; int salary; int height; int bossId; int sub;};bool func1(const Person& p1, const Person& p2){ retu原创 2009-12-05 22:34:00 · 664 阅读 · 0 评论 -
pku 1270 Following Orders DFS+拓扑排序
题意很清晰.可以利用dfs遍历每一组值,然后加上剪枝条件.由于剪枝可以利用当前节点和已遍历节点的顺序关系,可以使用拓扑排序. 注意: 输入的第一行不一定是有序的,我在这里sort了一下才过. 小结: 拓扑排序用于当序列中的元素有顺序关系时求可行的序列. #include #include #include using namespace std;原创 2009-12-05 18:48:00 · 772 阅读 · 0 评论 -
pku 3687 Labeling Balls 逆序拓扑排序
这题的题意确实有点难懂.For each test case output on a single line the balls weights from label 1 to label N. If several solutions exist:要注意要求输出的是球1~N的重量.you should output the one with the smallest weight原创 2009-12-05 11:15:00 · 1347 阅读 · 0 评论 -
拓扑排序 标程
int edge[][]; //图的邻接矩阵int in_degree[n]; //顶点的入度//拓扑排序void TopoOrder(int n){ int top = -1; for (int i = 0; i < n; ++i) if (in_degree[i] == 0) { in_degree[i] = top; top = i;原创 2009-12-04 23:09:00 · 599 阅读 · 0 评论 -
pku 1674 Sorting by Swapping
#include #include #include using namespace std;int map[10005];int main(){ int N, n; scanf("%d", &N); while(N--) { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d",原创 2009-04-24 10:29:00 · 571 阅读 · 0 评论 -
pku 1057 文件结构问题
#include #include #include #include using namespace std;string s;struct Directory{ string name; vector menu; vector files;};void build(Directory& t, string s){ if(s == "*"原创 2009-03-30 21:36:00 · 889 阅读 · 2 评论 -
pku 1426 bfs
#include using namespace std;__int64 q[1100000];int n;__int64 bfs(){ int front = 0, rear = 0; q[rear++] = 1; while(front < rear) { __int64 temp = q[front++]; if(temp % n == 0)原创 2009-04-01 19:01:00 · 741 阅读 · 0 评论 -
pku 2255 二叉树的三种遍历
#include #include #include using namespace std;string s1, s2;typedef struct TNode{ char data; struct TNode *lchild, *rchild;}*BTree;void build(BTree& T, int start1, int end1, int s原创 2009-03-18 12:45:00 · 897 阅读 · 0 评论 -
pku 2309 BST 位操作
#include using namespace std;int Lowbit(int t) {//t后零的个数为k,返回2^k return t & ( t ^ ( t - 1 ) ); }int main(){ int n; int node; scanf("%d", &n); while(n--) { scanf("%d", &no原创 2009-03-15 00:15:00 · 667 阅读 · 0 评论 -
pku 1456 Supermarket
#include #include #include using namespace std;#define N 10005struct Product{ int profit; int deadline; bool operator < (const Product& rhs) const { return deadline < rhs.deadli原创 2010-05-20 18:55:00 · 627 阅读 · 0 评论