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;}
}T[N];
char s[233];
int n; inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} int build(int n){
for(int i=1,j;i<=n;++i){
for(j=i-1;T[j].fix<T[i].fix;j=T[j].fa);
T[i].l=T[j].r;
T[j].r=i;
T[i].fa=j;
}
return T[0].r;
} void dfs(int u){
if(!u) return;
printf("(");
dfs(T[u].l);
printf("%s/%d",T[u].s,T[u].fix);
dfs(T[u].r);
printf(")");
} int main(){
while(~scanf("%d",&n)&&n){
for(int i=0;i<=n;T[i++].clear());
T[0].fix=1e9;
for(int i=1;i<=n;++i){
scanf("%s",s);
sscanf(s,"%[^/]/%d",T[i].s,&T[i].fix);
}
sort(T+1,T+n+1);
int rt=build(n);
dfs(rt);puts("");
}
return 0;
}

[POJ1785]Binary Search Heap Construction(笛卡尔树)的更多相关文章

  1. POJ-1785-Binary Search Heap Construction(笛卡尔树)

    Description Read the statement of problem G for the definitions concerning trees. In the following w ...

  2. poj1785 Binary Search Heap Construction

    此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cs ...

  3. 笛卡尔树 POJ ——1785 Binary Search Heap Construction

    相应POJ 题目:点击打开链接 Binary Search Heap Construction Time Limit: 2000MS   Memory Limit: 30000K Total Subm ...

  4. ZOJ - 2243 - Binary Search Heap Construction

    先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the sta ...

  5. POJ 1785 Binary Search Heap Construction(裸笛卡尔树的构造)

    笛卡尔树: 每个节点有2个关键字key.value.从key的角度看,这是一颗二叉搜索树,每个节点的左子树的key都比它小,右子树都比它大:从value的角度看,这是一个堆. 题意:以字符串为关键字k ...

  6. POJ 1785 Binary Search Heap Construction (线段树)

    题目大意: 给出的东西要求建立一个堆,使得后面的数字满足堆的性质.并且字符串满足搜索序 思路分析: 用线段树的最大询问建树.在建树之前先排序,然后用中序遍历递归输出. 注意输入的时候的技巧. .. # ...

  7. 平衡树及笛卡尔树讲解(旋转treap,非旋转treap,splay,替罪羊树及可持久化)

    在刷了许多道平衡树的题之后,对平衡树有了较为深入的理解,在这里和大家分享一下,希望对大家学习平衡树能有帮助. 平衡树有好多种,比如treap,splay,红黑树,STL中的set.在这里只介绍几种常用 ...

  8. Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题

    D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...

  9. codevs2178 表达式运算Cuties[笛卡尔树]

    2178 表达式运算Cuties  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 大师 Master 题解  查看运行结果     题目描述 Description 给出一个表达 ...

随机推荐

  1. ring0 关于SSDTHook使用的绕过页面写保护的原理与实现

    原博:http://www.cnblogs.com/hongfei/archive/2013/06/18/3142162.html 为了安全起见,Windows XP及其以后的系统将一些重要的内存页设 ...

  2. June 16th 2017 Week 24th Friday

    Progress is the activity of today and the assurance of tomorrow. 进步是今天的活动,明天的保证. The best preparatio ...

  3. March 5 2017 Week 10 Sunday

    If you do what you love, you will never work a day in your life. 做你所爱的事情,你就不会觉得是在工作. Today, one mach ...

  4. 如何删除Windows 10中的内存转储文件

    内存转储文件是由Windows产生的.以下情况下可能产生内存转储文件: 计算机崩溃蓝屏 内存错误 硬件问题 内存转储文件包含计算机系统崩溃时的详细的参数副本.用于帮助识别导致系统崩溃的原因.Windo ...

  5. WPF产生不重复的随机数

    WPF产生不重复的随机数 在给定的区间范围(比如[50,99]),产生给定数量的随机数(不如10个),要求产生的随机数不重复首先给定变量min=50;max=99+1;//习惯与程序规定的编码不同所致 ...

  6. ORACLE常用函数汇总(持续更新中....)

    在使用ORACLE过程中,把一些常用的函数的相关用法,注意事项进行简单的汇总,便于自己查询参考. DBMS_RANDOM包 dbms_random是一个可以生成随机数值或者字符串的程序包.这个包有in ...

  7. iOS UI(布局)约束是什么?view1.attr1 = view2.attr2 * multiplier + constant

    /* Create constraints explicitly.  Constraints are of the form "view1.attr1 = view2.attr2 * mul ...

  8. 【洛谷5283】[十二省联考2019] 异或粽子(可持久化Trie树+堆)

    点此看题面 大致题意: 求前\(k\)大的区间异或和之和. 可持久化\(Trie\)树 之前做过一些可持久化\(Trie\)树题,结果说到底还是主席树. 终于,碰到一道真·可持久化\(Trie\)树的 ...

  9. nbu集群Alwayson相关问题

    Alwayson 1. Alwayson 是否依赖于域环境? 答: 是, alwayson依赖于故障转移群集(只有在故障转移群集中的SQL Server 才能启动高可行性组功能),而故障转移群集愈依赖 ...

  10. c#用链表存储并读取配置文件(代码部分)

    //读取配置参数 private void loadcofig() { //List<param> camra1 = new List<param>(); List<st ...