原题链接: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. CISCO动态VLAN配置

    一.基于VMPS的动态VLAN配置实例 网络中VLAN实现分为静态 VLAN和动态VLAN.静态VLAN又被称为是基于端口的VLAN.顾名思义,就是明确指定各端口属于哪个VLAN的设定方法,交换机中某 ...

  2. 学习资料 数据查询语言DQL

    数据查询语言DQL介绍及其应用: 查询是SQL语言的核心,SQL语言只提供唯一一个用于数据库查询的语句,即SELECT语句.用于表达SQL查询的SELECT语句是功能最强也是最复杂的SQL语句,它提供 ...

  3. spring HibernateValidator 验证 子类不起作用

    spring HibernateValidator 验证 子类不起作用,在要验证的子类前加上@Valid即可. public class UserInfo { private int Id; @Val ...

  4. 如何用ASPxTreeView建立三级树(显示及数据绑定)

    示例如图: //设置treeviw默认为第一个菜单打开if (ASPxTreeView1.SelectedNode == null)ASPxTreeView1.SelectedNode = ASPxT ...

  5. C/C++中几种操作位的方法

    参考How do you set, clear and toggle a single bit in C? c/c++中对二进制位的操作包括设置某位为1.清除某位(置为0).开关某位(toggling ...

  6. vyos (一) 基础配置

    http://www.lowefamily.com.au/2015/11/29/using-a-vyos-router-with-hyper-v/1/ http://thomasvochten.com ...

  7. iptable防火墙配置

    /etc/sysconfig/iptables /etc/init.d/iptables {start|stop|restart|condrestart|status|panic|save} ipta ...

  8. js object 对象 属性和方法的使用

    //object 对象 属性和方法的使用 var person = new Object(); person.name="张海"; person.age="; perso ...

  9. [转载]word尾注插入参考文献——前人经验+自己总结

    1. 以尾注的方式插入第一个参考文献. 将光标定位于word文档中将要插入参考文献的位置,按“插入/引用/脚注和尾注”.出现一菜单,选择“尾注”,“文档结尾”,编号格式为“1,2,3”.按“插入”按钮 ...

  10. WP8_UTF8 to GB2312转码 (url网址中带中文字符的处理)

    直接使用例如:http://www.abc.php?name=中文符 ,客户端调用,在服务端修改后,会出现乱码, 而windows phone 又不能直接支持gb2312, 经过大量分析和验证,发现 ...