原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1622 
小白书上的题。。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<queue>
using std::queue;
using std::vector;
const int Max_N = ;
struct Node {
int v, vis;
Node *ch[];
inline void set(int _v, Node *p) {
vis = , v = _v;
ch[] = ch[] = p;
}
};
struct BinTree {
int fail;
char buf[Max_N];
Node *tail, *root, stack[Max_N];
void init() {
fail = ;
tail = &stack[];
}
inline Node *newNode(int v = ) {
Node *p = tail++;
p->set(v, NULL);
return p;
}
inline void insert(const char *src, const int v) {
int n = strlen(src);
Node *x = root;
for (int i = ; i < n; i++) {
if (src[i] == 'L') {
if (!x->ch[]) x->ch[] = newNode();
x = x->ch[];
} else if (src[i] == 'R') {
if (!x->ch[]) x->ch[] = newNode();
x = x->ch[];
}
}
if (x->vis) fail = ;
x->v = v;
x->vis = ;
}
inline void bfs() {
vector<int> ans;
queue<Node *> que;
que.push(root);
while (!que.empty()) {
Node *u = que.front(); que.pop();
if (!u->vis) {
fail = ;
break;
}
ans.push_back(u->v);
if (u->ch[]) que.push(u->ch[]);
if (u->ch[]) que.push(u->ch[]);
}
if (fail) {
puts("not complete");
return;
}
int n = ans.size();
for (int i = ; i < n; i++) {
printf("%d%c", ans[i], i < n - ? ' ' : '\n');
}
}
inline int gogo() {
init();
int v = ;
root = newNode();
for (;;) {
if (scanf("%s", buf) != ) return ;
if (!strcmp(buf, "()")) break;
sscanf(&buf[], "%d", &v);
insert(strchr(buf, ',') + , v);
}
bfs();
return ;
}
}tree;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
while (tree.gogo());
return ;
}

hdu 1622 Trees on the level的更多相关文章

  1. hdu 1622 Trees on the level(二叉树的层次遍历)

    题目链接:https://vjudge.net/contest/209862#problem/B 题目大意: Trees on the level Time Limit: 2000/1000 MS ( ...

  2. 【二叉树】hdu 1622 Trees on the level

    [题意] 给定一棵树每个结点的权重和路径(路径用LR串表示),输出这棵树的层次遍历 [思路] 注意输入输出,sscanf用来格式化地截取需要的数据,strchr来在字符串中查找字符的位置 [Accep ...

  3. [ An Ac a Day ^_^ ] hdu 1662 Trees on the level 数据结构 二叉树

    紫书上的原题 正好学数据结构拿出来做一下 不知道为什么bfs的队列一定要数组模拟…… 还可以练习一下sscanf…… #include<stdio.h> #include<iostr ...

  4. Trees on the level(指针法和非指针法构造二叉树)

    Trees on the level Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. E - Trees on the level

     Trees on the level  Background Trees are fundamental in many branches of computer science. Current ...

  6. UVA.122 Trees on the level(二叉树 BFS)

    UVA.122 Trees on the level(二叉树 BFS) 题意分析 给出节点的关系,按照层序遍历一次输出节点的值,若树不完整,则输出not complete 代码总览 #include ...

  7. Trees on the level UVA - 122 复习二叉树建立过程,bfs,queue,strchr,sscanf的使用。

    Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- ...

  8. UVA 122 -- Trees on the level (二叉树 BFS)

     Trees on the level UVA - 122  解题思路: 首先要解决读数据问题,根据题意,当输入为“()”时,结束该组数据读入,当没有字符串时,整个输入结束.因此可以专门编写一个rea ...

  9. uva 122 trees on the level——yhx

    题目如下:Given a sequence of binary trees, you are to write a program that prints a level-order traversa ...

随机推荐

  1. com学习前提必看

    1) COM组件实际上是一个C++类,而接口都是纯虚类.组件从接口派生而来.我们可以简单的用纯粹的C++的语法形式来描述COM是个什么东西: class IObject { public: virtu ...

  2. windows 10 笔记本关机不断电解决

    右键我的电脑-->管理-->设备管理器-->系统设备 找到Intel(R) Management Engine Interface  双击打开,禁用,确定,完事 原因,该驱动11.0 ...

  3. C# 枚举显示中文

    转自:http://www.cnblogs.com/yank/archive/2011/09/08/EnumDisplayInChinese.html   using System; using Sy ...

  4. Android基础总结(5)——数据存储,持久化技术

    瞬时数据:指那些存储在内存当中,有可能会因为程序广播或其他原因导致内存被回收而丢失的数据. 数据持久化:指将那些内存中的瞬时数据保存到存储设备中,保证即使在手机或电脑关机的情况下,这些数据仍然不丢失. ...

  5. ASP.NET MVC4 学习系统一(项目模板)

    项目模板 1.空模板      空模板用于创建ASP.NETMVC 4网站的架构,包含基本的文件夹结构,以及需要引用的asp.netmvc程序集,也包含可能要使用的javaScript 库.模板同样包 ...

  6. java基础回顾(三)——HashMap与HashTable

    public class Hashtable extends Dictionary implements Map, Cloneable, java.io.Serializable public cla ...

  7. hdu2571

    if(x==1) f(x,y)=max{f(x,y-1),f(x,z)}  {y%z==0&&1<y/z<=y&&1<=z<<y} els ...

  8. css初涉

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. linq to xml 基本操作

    使用XDocument类来进行简单的xml操作,用于软件参数的设置保存. using System; using System.Collections.Generic; using System.Li ...

  10. C# 平时碰见的问题【4】

    1. 模糊查询 like的参数化写法 string keyword="value"; // 要模糊匹配的值 错误示范:   sql:    string strSql=" ...