ZOJ 1700 Falling Leaves 树形结构
来源:互联网 发布:淘宝优惠卷软件挣钱 编辑:程序博客网 时间:2024/06/06 04:42
做法:看清题意即可。
#include<cstdio>#include<cstring>const int LMT=30;int head,cnt,tr,lev;struct node{int l,r,data;}nod[LMT];char ans[LMT],sec[LMT][LMT];void init(){int i;for(i=0;i<LMT;i++)nod[i].l=nod[i].r=-1;memset(ans,0,sizeof(ans));tr=head=0;lev=0;cnt=1;}void dfs(int pos,int pre,int is_left,int val){if(pos==-1){if(is_left)nod[pre].l=cnt;else nod[pre].r=cnt;nod[cnt].data=val;cnt++;return;}if(val>nod[pos].data)dfs(nod[pos].r,pos,0,val);else dfs(nod[pos].l,pos,1,val);}void see(int u){if(u==-1)return;ans[tr]=nod[u].data+'A';tr++;see(nod[u].l);see(nod[u].r);}int main(void){int j,i=0;init();while(~scanf("%s",sec[lev])&&strcmp(sec[lev],"*")&&strcmp(sec[lev],"$")){if(!strcmp(sec[lev],"$"))break;if(!strcmp(sec[lev],"*"))continue;lev++;while(~scanf("%s",sec[lev])&&strcmp(sec[lev],"*")&&strcmp(sec[lev],"$"))lev++;nod[head].data=sec[lev-1][0]-'A';for(i=lev-2;i>=0;i--)for(j=0;sec[i][j];j++)dfs(head,-1,-1,sec[i][j]-'A');see(head);printf("%s\n",ans);if(!strcmp(sec[lev],"$"))break;init();}return 0;}
- ZOJ 1700 Falling Leaves 树形结构
- ZOJ 1700 Falling Leaves
- ZOJ-1700 falling leaves
- ZOJ 1700 Falling Leaves
- zoj 1700 || poj 1577 Falling Leaves(BST)
- zoj 1700 || poj 1577 Falling Leaves(BST应用)
- ZOJ 1700 Falling Leaves 二叉搜索树+前序遍历
- 699 - The Falling Leaves
- 699 - The Falling Leaves
- UVA699 - The Falling Leaves
- uva_699_The Falling Leaves
- uva_699-The Falling Leaves
- POJ-1577-Falling Leaves
- UVaOJ699---The Falling Leaves
- poj1577 Falling Leaves
- POJ 1577 Falling Leaves
- PKU 1577 Falling Leaves
- UVa699 The Falling Leaves
- Cannot load php5apache2.dll into server Apache is running a threaded MPM,
- php类型
- woj1010- Alternate Sum
- 中国象棋 军 规则判断
- 内存映射文件(Memory-Mapped Files)
- ZOJ 1700 Falling Leaves 树形结构
- 精通git中文版(连载十七)
- Flex学习篇之一:初识Flex
- 求多个数最小公倍数的一种变换算法
- DepartmentDaoImpl
- 入住CSDN博客
- python中web应用程序与web服务
- PHP中常用的数组函数
- java位运算