uva 1556 - Disk Tree(特里)
题目大意:给出N个文件夹关系,然后依照字典序输出整个文件文件夹。
解题思路:以每一个文件夹名作为字符建立一个字典树就可以,每一个节点的关系能够用map优化。
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 50005;
typedef map<string, int>::iterator iter;
struct Tire {
int sz;
map<string, int> g[maxn];
void init();
void insert(string s);
void put(int u, int d);
}tree;
int main () {
int n;
string s;
while (cin >> n && n) {
tree.init();
for (int i = 0; i < n; i++) {
cin >> s;
s += '\\';
tree.insert(s);
}
tree.put(0, 0);
cout << endl;
}
return 0;
}
void Tire::init() {
sz = 1;
g[0].clear();
}
void Tire::insert(string s) {
int u = 0;
string word = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == '\\') {
if (!g[u].count(word)) {
g[sz].clear();
g[u][word] = sz++;
}
u = g[u][word];
word = "";
} else
word += s[i];
}
}
void Tire::put (int u, int d) {
for (iter i = g[u].begin(); i != g[u].end(); i++) {
for (int j = 0; j < d; j++)
cout << " ";
cout << i->first << endl;
put(i->second, d + 1);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
uva 1556 - Disk Tree(特里)的更多相关文章
- ural1067 Disk Tree
Disk Tree Time limit: 2.0 secondMemory limit: 64 MB Hacker Bill has accidentally lost all the inform ...
- POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)
Tree Summing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8132 Accepted: 1949 Desc ...
- UVA 11922 Splay tree
UVA 11922 题意: 有n个数1~n 操作a,b表示取出第a~b个数,翻转后添加到数列的尾部 输入n,m 输入m条指令a,b 输出最终的序列 代码: #include<iostream&g ...
- HDU 1504 Disk Tree
转载请注明出处:http://blog.csdn.net/a1dark 分析:查了一下这题.发现网上没有什么关于这道题的解题报告.其实题目意思挺好懂的.就是给你一些文件的目录结构.然后让你把它们组合在 ...
- 1067. Disk Tree(字符串)
1067 破题啊 写完发现理解错题意了 子目录下会有跟之前重名的 把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 #include <iostream> #include< ...
- 【HDOJ】1504 Disk Tree
文件可以重名.先按字典序将路径排序,再过滤掉公共前缀.其中的问题是'\'的ASCII比[A-Z0-9]大,将它替换为空格.否则字典序有问题. /* 1504 */ #include <iostr ...
- 【UVA】536 Tree Recovery(树型结构基础)
题目 题目 分析 莫名A了 代码 #include <bits/stdc++.h> using namespace std; string s1,s2; void buil ...
- uva 6910 - Cutting Tree 并查集的删边操作,逆序
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【习题 6-11 UVA - 10410】Tree Reconstruction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以先确定当前这棵子树的dfs序的范围. 然后第一个元素肯定是这棵子树的根节点. 那么只要在这棵子树的范围里面枚举节点. 看看有没有 ...
随机推荐
- 在MyEclipse8.5中配置Tomcat6.0服务器
一.单击工具栏的的黑小三角,选择—>Configure Server,出现首选项对话框,在对话框的左边框中找到MyEclipse—>Application Servers下找到Tomcat ...
- Test SRM Level Three: LargestCircle, Brute Force
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3005&rd=5858 思路: 如果直接用Brute F ...
- poj 1962 Corporative Network
主题链接:http://poj.org/problem?id=1962 思路:每一个集合中用根节点标记这个集合,每一个点到根节点的距离. code: <span style="font ...
- [LeetCode238]Product of Array Except Self
题目: Given an array of n integers where n > 1, nums, return an array output such that output[i] is ...
- 在 VS 类库项目中 Add Service References 和 Add Web References 的区别
原文:在 VS 类库项目中 Add Service References 和 Add Web References 的区别 出身问题: 1.在vs2005时代,Add Web Reference(添加 ...
- dev layoutControl 控件使用
对于排版控件,用微软的方法都是先拉 label再拉一个 Textbox , 虽然微软的控件了有类似于 EXCEL的单元格全并功能,但用起来使终不方便, 今天研究了一下 DEV 的这个控件,比微软的 ...
- GUI (图形界面)知识点
一:组件知识点 JTextField: 作用: 定义文本域,只支持单行输入. 使用: 定义文本域: JTextField jtf=new JTextField ...
- 低压电力采集平台DW710C与PC沟通
集电极485接口RS-485与RS-232转换模块485端相连.RS-485与RS-232转换模块232通过串行电缆末端PC的232串口.我们通过书面沟通PC通信软件来实现双方并执行收购方案. 1)上 ...
- 使用 node-inspector 调试 Node.js
大部分基于 Node.js 的应用都是执行在浏览器中的, 比如强大的调试工具 node-inspector. node-inspector 是一个全然基于 Node.js 的开源在线调试工具,提供了强 ...
- leetcode第一刷_Minimum Path Sum
能够用递归简洁的写出,可是会超时. dp嘛.这个问题须要从后往前算,最右下角的小规模是已知的,边界也非常明显,是最后一行和最后一列,行走方向的限制决定了这些位置的走法是唯一的,能够先算出来.然后不断的 ...