[POJ1785]Binary Search Heap Construction(笛卡尔树)
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(笛卡尔树)的更多相关文章
- POJ-1785-Binary Search Heap Construction(笛卡尔树)
Description Read the statement of problem G for the definitions concerning trees. In the following w ...
- poj1785 Binary Search Heap Construction
此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cs ...
- 笛卡尔树 POJ ——1785 Binary Search Heap Construction
相应POJ 题目:点击打开链接 Binary Search Heap Construction Time Limit: 2000MS Memory Limit: 30000K Total Subm ...
- ZOJ - 2243 - Binary Search Heap Construction
先上题目: Binary Search Heap Construction Time Limit: 5 Seconds Memory Limit: 32768 KB Read the sta ...
- POJ 1785 Binary Search Heap Construction(裸笛卡尔树的构造)
笛卡尔树: 每个节点有2个关键字key.value.从key的角度看,这是一颗二叉搜索树,每个节点的左子树的key都比它小,右子树都比它大:从value的角度看,这是一个堆. 题意:以字符串为关键字k ...
- POJ 1785 Binary Search Heap Construction (线段树)
题目大意: 给出的东西要求建立一个堆,使得后面的数字满足堆的性质.并且字符串满足搜索序 思路分析: 用线段树的最大询问建树.在建树之前先排序,然后用中序遍历递归输出. 注意输入的时候的技巧. .. # ...
- 平衡树及笛卡尔树讲解(旋转treap,非旋转treap,splay,替罪羊树及可持久化)
在刷了许多道平衡树的题之后,对平衡树有了较为深入的理解,在这里和大家分享一下,希望对大家学习平衡树能有帮助. 平衡树有好多种,比如treap,splay,红黑树,STL中的set.在这里只介绍几种常用 ...
- 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 ...
- codevs2178 表达式运算Cuties[笛卡尔树]
2178 表达式运算Cuties 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description 给出一个表达 ...
随机推荐
- 【Leetcode】【Easy】Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- Docker 容器中相关软件安装
Docker 容器中相关软件安装 1.介绍 我们从docker hub下载的centos镜像是只有很少的命令,需要单独安装我们所需的相关软件. 2.安装软件 安装yum-utils软件包 该软件包是辅 ...
- Windows平台,Oracle Database和Client并存方式
由于某些特定需求,生产环境需要在同一台机器上同时安装Database Server和Client,因为plsql没有64位客户端,无法读取64位database的oci.dll文件,所以需要一个32位 ...
- 初见git和github
一.我的github helloworld程序的地址:https://github.com/wyf1213/wyf-project1 二.git/github的相关介绍资料 1.github是什么 ...
- Android(java)学习笔记40:WindowManager 中LayoutParams的各种属性
1. WindowManager 中LayoutParams的各种属性 WindowManager.LayoutParams 是 WindowManager 接口的嵌套类(内部类):它继承于 View ...
- 【[HEOI2016/TJOI2016]游戏】
据说是网络流棋盘模型了 我们把每一个连续子段都看成一个点,我们先把所有的行上的连续子段找出来给他们编上号,所有列上的连续子段找出来也编上号 现在每个格子都有两个编号了,\(a[i][j]\)表示行所对 ...
- 从命令行运行Jmeter及jmeter参数说明、Html报告生成
为什么要命令行执行脚本,主要有以下三点: 1) 图形化界面消耗更多资源,CPU和内存 2) 图形化界面不支持大型的负载测试和性能测试 3) 命令行测试支持持续集成,例如放到Jenkins这样的CI工具 ...
- WebNotes(PHP、css、JavaScript等)
1. 数据库编码格式 gb-2312仅支持简体中文,GBK支持简体.繁体中文,utf-8通用程度最高. 2. HTTP请求方法 get方法请求时,会将传输的数据跟在链接后“显式地”发送,受限于链接长度 ...
- 【luoguP1086】【2004NOIP-Ua】花生采摘
P1086 花生采摘 题目描述 鲁宾逊先生有一只宠物猴,名叫多多.这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着一张小小的纸条:“欢迎免费品尝我种的花生!――熊字”. 鲁宾逊先生和多多都 ...
- java容易混淆的的内部类相关概念
关于内部类: 作用: 1. 内部类提供了更好的封装,可以把内部类隐藏在外部类之内,不允许同一个包中的其他类访问该类 2. 内部类的方法可以直接访问外部类的所有数据,包括私有的数据 3. 内部类所实现的 ...