相应POJ 题目:点击打开链接 Binary Search Heap Construction Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 9075   Accepted: 2566 Description Read the statement of problem G for the definitions concerning trees. In the following we define the basic…
笛卡尔树: 每个节点有2个关键字key.value.从key的角度看,这是一颗二叉搜索树,每个节点的左子树的key都比它小,右子树都比它大:从value的角度看,这是一个堆. 题意:以字符串为关键字key,数字为关键字value,构造一个二叉搜索大堆,最后按要求中序遍历 笛卡尔树的构造. 建立笛卡尔树的O(n)的算法: 从别人博客里拷贝过来的,这里给出链接:http://hi.baidu.com/yy17yy/item/cd4edcf963944f6a3d148553 首先按key关键字进行排序…
Description Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal nodes have each assigned a priority (a number) such that the priority of each…
题目大意: 给出的东西要求建立一个堆,使得后面的数字满足堆的性质.并且字符串满足搜索序 思路分析: 用线段树的最大询问建树.在建树之前先排序,然后用中序遍历递归输出. 注意输入的时候的技巧. .. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define lson num<<1,s,mid #define rson num<&l…
先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n…
Code #include <cstdio> #include <algorithm> #include <cstring> #define N 500010 using namespace std; struct info{ int fix,l,r,fa; char s[10]; friend bool operator <(info a,info b){ return strcmp(a.s,b.s)<0; } void clear(){l=r=fa=0;…
此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; struct Point{ ]; int pr; bool operator < (const Point& rhs) const{ ; } }a[maxn]; struct…
[题目分析] 本来是单调栈的题目,用笛卡尔树可以快速的水过去. 把每一个矩阵看成一个二元组(出现的顺序,高度). 然后建造笛卡尔树. 神奇的发现,每一个节点的高度*该子树的大小,就是这一块最大的子矩阵的可能解. 用二元组的第一个下标来限制,使它们在一块儿,然后堆的性质又限制了宽度以及高度. 计算,取最值即可. [代码] #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath&g…
[题目分析] 构造一颗笛卡尔树,然后输出这棵树即可. 首先进行排序,然后用一个栈维护最右的树的节点信息,插入的时候按照第二关键字去找,找到之后插入,下面的树成为它的左子树即可. 然后插入分三种情况讨论(最下面,中间,成为了新的树根) [代码] #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; struct nod…
链接 捣鼓了一下午..按堆建树 写完交 返回TLE..数据不大 感觉不会超了 无奈拿了数据来看什么奇葩数据会超 发现数据跟我输出不一样 看了好久才明白理解错题意了 给出的字符串有两个标签 按前一个来建二叉搜索树 按后一个建堆 搜索树直接排序 然后依次插入右子树  若当前值比前一个的值大 就在与其父亲比较 总之放到合适位置. 这样的树叫笛卡尔树 #include<iostream> #include<cstdio> #include<cstring> #include&l…