
数据结构
coldfresh
那我们开始吧
展开
-
Largest Rectangle in a Histogram (POJ - 2559 )(栈)
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows t原创 2017-05-02 14:29:19 · 433 阅读 · 0 评论 -
Data Structure? HDU - 4217(树状数组+二分)
Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data in a computer so that it can be used efficiently. Today let me introdu...原创 2018-07-18 23:54:20 · 232 阅读 · 0 评论 -
Editor HDU - 4699 (模拟)
Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Output 2 3思路:就是模拟了,关键是怎么模拟了,这里用两个栈,如果左移就做边出栈,然后压到右边的栈。通过两个栈来模拟光标左右移动,其也就差不多了。 代码:#include<iostream>#include<cstdio>#include<sta...原创 2018-05-03 14:11:38 · 302 阅读 · 0 评论 -
Supermarket POJ - 1456 (堆)
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the s...原创 2018-04-01 22:58:09 · 410 阅读 · 0 评论 -
(pat)A1043. Is It a Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:1.The left subtree of a node contains only nodes with keys less than the node’s key. 2.The righ...原创 2018-03-06 17:54:10 · 202 阅读 · 0 评论 -
二叉搜索树(BST)的相关操作
今天写一写二叉搜索树的插入,查找,删除的操作。 首先给出节点的数据结构struct node{ int data; node*l; node* r;};第一个是查找操作:void search(node* root,int x){ if(root==NULL) { printf("no"); ret...原创 2018-03-06 16:25:20 · 215 阅读 · 0 评论 -
(pat)A1053 Path of Equal Weight
Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to...原创 2018-03-05 21:57:46 · 184 阅读 · 0 评论 -
(pat)A1020. Tree Traversals
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the cor...原创 2018-03-05 20:45:50 · 196 阅读 · 0 评论 -
二叉树建树的若干问题
问题1二叉树有一种问题很经典,如果给出中序遍历和前序遍历的序列,如果建立一个颗二叉树数?(实际上后续遍历和前序遍历是一样的,可以替换掉前序遍历的)那么我们容易知道,前序遍历序列的第一个节点就是root,那么我们在中序遍历找出这个点,那么在这个店的做边就是左子树的中序遍历序列,右边亦然,那么前序遍历在除掉第一个点以后与左子树的中序遍历序列相同数量想对应,构成一个规模缩小,但是问题一致的子问题,所...原创 2018-03-05 17:59:17 · 330 阅读 · 0 评论 -
(pat)A1052. Linked List Sorting(静态链表)
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now give...原创 2018-03-04 19:45:01 · 175 阅读 · 0 评论 -
二叉平衡树(AVL)的插入
这次节点的数据域增加了高度这个量,用来计算平衡因子,以此在插入的时候来调整树的结构 节点:struct node{ int val; int hei; node *l; node *r;};构造新节点node* newNode(int v){ node* Node=new node; Node->val=v; N...原创 2018-03-06 19:14:00 · 252 阅读 · 0 评论 -
AC自动机(Trie图)
传送门输入 每个输入文件有且仅有一组测试数据。每个测试数据的第一行为一个整数N,表示河蟹词典的大小。接下来的N行,每一行为一个由小写英文字母组成的河蟹词语。接下来的一行,为一篇长度不超过M,由小写英文字母组成的文章。对于60%的数据,所有河蟹词语的长度总和小于10, M<=10对于80%的数据,所有河蟹词语的长度总和小于10^3, M<=10^3对于100%的数据,所有河蟹词语的长度总和小于10^原创 2017-12-23 20:22:22 · 651 阅读 · 1 评论 -
Aragorn's Story HDU - 3966(树链剖分)
Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps out原创 2017-10-09 23:25:25 · 261 阅读 · 0 评论 -
Query on a tree SPOJ - QTREE(树链剖分)
传送门 题意:给定一棵树,告诉了每条边的权值,然后给出两种操作: (1)把第i条边的权值改为val (2)询问a,b路径上权值最大的边 假期之后的第一篇题解,只学习了一种新的数据结构,树链剖分,此题为入门题,这个我算是学习的最晚的一个人了。这个有种调用了线段的API的感觉#include<cstdio>#include<cstring>#include<algorithm>#inclu原创 2017-10-09 15:48:12 · 345 阅读 · 0 评论 -
统计难题 HDU - 1251 (字典树)
Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input 输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每个提问都是一个字符串. 注意:原创 2017-09-18 17:53:42 · 431 阅读 · 0 评论 -
可持久化数组(主席树基础)
题目链接大概是知道了可持久化是什么意思了代码:#include<stdio.h>#include<iostream>#include<cstring>#include<algorithm>#include<queue>#include<cmath>#include<vector>#include...原创 2019-08-05 21:03:11 · 219 阅读 · 0 评论