poj 2201 笛卡尔树
来源:互联网 发布:扫描编辑软件 编辑:程序博客网 时间:2024/05/16 19:57
这个数据结构看上去非常巧妙,不过没有找到实用的例题。。。。
#include<iostream>#include<cstdio>#include<algorithm>#define maxn 50005using namespace std;struct Pair{ int key,aux,id; int fa,ch[2]; void print() {printf("%d %d %d\n",fa,ch[0],ch[1]);}}p[maxn];bool cmp(Pair A,Pair B){return A.key<B.key;}bool cmp2(Pair A,Pair B){return A.id<B.id;}int S[maxn],top;int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) { read(p[i].key); read(p[i].aux); p[i].id=i; } sort(p+1,p+n+1,cmp); for(int i=1;i<=n;i++) { while(top) { if(p[S[top]].aux<p[i].aux) break; top--; } int f=S[top]; int t=p[f].ch[1]; p[f].ch[1]=i; p[i].fa=f; p[t].fa=i; p[i].ch[0]=t; S[++top]=i; } for(int i=1;i<=n;i++) { int x=p[i].fa;p[i].fa=p[x].id; x=p[i].ch[0];p[i].ch[0]=p[x].id; x=p[i].ch[1];p[i].ch[1]=p[x].id; } sort(p+1,p+n+1,cmp2); puts("YES"); for(int i=1;i<=n;i++) p[i].print(); return 0;}
1 0
- poj 2201 笛卡尔树
- poj 2201 笛卡尔树
- poj 2201 笛卡尔树
- POJ 2201 RMQ 笛卡尔树
- poj 2201(RMQ+笛卡尔树)
- POJ-2201 Cartesian Tree【笛卡尔树】
- POJ 2201 Cartesian Tree 笛卡尔树
- POJ 2201 Cartesian Tree 【笛卡尔树】
- POJ 2201 Cartesian Tree (笛卡尔树)
- POJ-2201-Cartesian Tree(笛卡尔树)
- POJ 2201 Cartesian Tree 笛卡尔树
- POJ-2201 Cartesian Tree(笛卡尔树)
- poj 2201 Cartesian Tree 笛卡尔树
- POJ 2201 Cartesian Tree 笛卡尔树裸题加讲解
- 笛卡尔树
- 笛卡尔树
- 笛卡尔树
- 笛卡尔树
- 安卓访问浏览器数据
- 2017年度学习计划之一起快乐学习数据分析
- 为什么c语言第一个数组元素要从a[0]开始数起,不从a[1]数起呢?
- Java Swing简单样例
- 电子纸上位机C#
- poj 2201 笛卡尔树
- 40 个很有用的 Mac OS X Shell 脚本和终端命令
- 调整数组顺序使奇数位于偶数前面
- 使用ffmpeg 将纯H264保存为mp4
- 欢迎使用CSDN-markdown编辑器
- 关于Ubuntu编译Qt失败问题
- java 反射机制
- C++中static详解
- hibernate持久化状态