文件可以重名。先按字典序将路径排序,再过滤掉公共前缀。
其中的问题是'\'的ASCII比[A-Z0-9]大,将它替换为空格。否则字典序有问题。

 /* 1504 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct path_t {
char s[];
int len; friend bool operator< (const path_t& a, const path_t& b) {
return strcmp(a.s, b.s) < ;
}
} path_t; const int maxn = ;
char SP[];
path_t path[maxn]; int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t, n;
int mlen, len;
int i, j, k;
char name[];
int beg, nspace;
char *s, *ss; memset(SP, ' ', sizeof(SP)); scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i=; i<n; ++i) {
scanf("%s", path[i].s);
path[i].len = strlen(path[i].s);
for (j=; j<path[i].len; ++j)
if (path[i].s[j] == '\\')
path[i].s[j] = ' ';
path[i].s[path[i].len] = ' ';
}
sort(path, path+n);
rep(ii, , n) {
s = path[ii].s;
len = path[ii].len;
if (ii) {
ss = path[ii-].s;
mlen = min(len, path[ii-].len);
nspace = ;
beg = ;
for (i=; i<=mlen; ++i) {
if (s[i] != ss[i])
break;
if (ss[i] == ' ') {
nspace++;
beg = i + ;
}
}
} else {
beg = ;
nspace = ;
} i = beg;
j = ;
while (i <= len) {
if (s[i] == ' ') {
SP[nspace] = '\0';
name[j] = '\0';
printf("%s%s\n", SP, name);
SP[nspace++] = ' ';
j = ;
} else {
name[j++] = s[i];
}
++i;
}
}
if (t)
putchar('\n');
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】1504 Disk Tree的更多相关文章

  1. 【HDOJ】4601 Letter Tree

    挺有意思的一道题,思路肯定是将图转化为Trie树,这样可以求得字典序.然后,按照trie的层次求解.一直wa的原因在于将树转化为线性数据结构时要从原树遍历,从trie遍历就会wa.不同结点可能映射为t ...

  2. 【数据结构】B-Tree, B+Tree, B*树介绍 转

    [数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...

  3. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

  4. LG3690 【模板】Link Cut Tree (动态树)

    题意 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联通的 ...

  5. AC日记——【模板】Link Cut Tree 洛谷 P3690

    [模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...

  6. LG3690 【模板】Link Cut Tree 和 SDOI2008 洞穴勘测

    UPD:更新了写法. [模板]Link Cut Tree 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 后接两个整数(x,y),代表询问从x到y ...

  7. (RE) luogu P3690 【模板】Link Cut Tree

    二次联通门 : luogu P3690 [模板]Link Cut Tree 莫名RE第8个点....如果有dalao帮忙查错的话万分感激 #include <cstdio> #includ ...

  8. LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板

    P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...

  9. 【LeetCode】199. Binary Tree Right Side View 解题报告(Python)

    [LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/probl ...

随机推荐

  1. Hql 中实用查询时候 引号的使用

    出错代码://List vlist = this.getHibernateTemplate().find("from AndroidCustomer ct where ct.token = ...

  2. Objective-C 学习笔记(Day 2)

    ------------------------------------------- 如何根据题目准确完整清晰的声明一个类并实现给定的行为 /*  //下面这个程序教大家如何根据题目去声明一个类,并 ...

  3. C#中var类型

    var关键字是C#3.0新增的特性,当你不能确定自己需要使用的类型时,可以选择使用var var可以代替任何类型,var关键字指示编译器根据初始化语句右侧表达式推断变量类型 例: int a = 2 ...

  4. C 语言 查找一个字符串2在字符串1中出现的次数

    #include <stdio.h> #include <windows.h> int main() { ], b[]; char *temp; ; memset( a, ); ...

  5. ios - objective-c runtime之随笔

    今天身体不舒服,还顶着写这篇博客. 举个例子,我们之前在写objective-c代码时,经常用到id这个关键字.那 id 究竟是什么?在objective-c的运行时,这样描述的,它其实是一个结构体( ...

  6. 转:如何取得Spring管理的bean

    原文链接:http://blog.csdn.net/a9529lty/article/details/42145545 1.servlet方式加载时,[web.xml] <servlet> ...

  7. 谱曲软件-MuseScore

    谱曲软件-MuseScore 参考: 1.MuseScore官网 2.免费乐谱制作软体MuseScore

  8. makefile--#的不正确使用

    /usr/vacpp/bin/makeC++SharedLib -o /cicm/src/dao/testcase/rel/FUNCTEST.ibmcpp -brtl -bnortllib -p100 ...

  9. linux共享文件samba安装与java读取外部文件夹方法

    测试环境RedHat 6.4 一.安装 samba组件安装: (1)首先用“rpm –qa |grep samba”命令检验系统samba服务是否安装. #rpm –qa |grep samba sa ...

  10. SSH调试

    <s:date>标签中若是用date数组或Calendar数组,则永远显示数组最后一个数. 试试List.Set.Map也不行. 看来只能够使用单个对象.或者在后台传送String 数组, ...