博客
关于我
洛谷P1377树的序
阅读量:328 次
发布时间:2019-03-04

本文共 562 字,大约阅读时间需要 1 分钟。

洛谷P1377树的序

思路

4个数组保存一棵树
2个保存左右儿子
1个保存值
1个保存指针

CODE

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[100010][4];void DFS(int x){   	if(x==0)return;	cout<<x<<' ';	if(a[x][2])DFS(a[x][2]);	if(a[x][3])DFS(a[x][3]);	return;}int main(){   	ios::sync_with_stdio(false);	int i,n,len=0,tem;	memset(a,0,sizeof(a));	for(cin>>n,i=1; i<=n; i++)cin>>tem,a[tem][0]=i;	for(i=1; i<=n; i++)	{   		for(tem=len;tem&&a[a[tem][1]][0]>a[i][0];tem--);		if(tem)a[a[tem][1]][3]=i;		if(tem<len)a[i][2]=a[tem+1][1];		a[len=++tem][1]=i;	}	DFS(a[1][1]);	return 0;}

转载地址:http://wrze.baihongyu.com/

你可能感兴趣的文章
阿里云云解析DNS各种概念深度剖析
查看>>
SQLite基础用法
查看>>
(20200328已解决)从docker容器内复制文件到宿主机
查看>>
理解Docker ulimit参数
查看>>
pandas.groupby().rank()用法详解
查看>>
Factor Exposure因子暴露
查看>>
理解zvt in Python on Quant
查看>>
理解Data Centric VS. Document Centric VS. mixed-content XML
查看>>
理解DSL||AST||query clauses||X-Pack||JDBC||ODBC
查看>>
将DataFrame作为邮件正文HTML发送 in Python
查看>>
理解Library of Congress Cataloging-in-Publication Data
查看>>
理解Python系统下的时间格式
查看>>
《经济机器是怎样运行的》笔记(三)
查看>>
prod()与cumprod()区别cumsum()
查看>>
Python提升回测速度concurrnet.futures模块详解
查看>>
Python语言'类'概念再理解
查看>>
(2019.6.27)Anaconda清华镜像已恢复使用
查看>>
Robomongo使用教程:踩着前辈的路
查看>>
Python中Class类与def函数的区别
查看>>
OpenAI Gym简介及初级实例
查看>>