【HDOJ】1504 Disk Tree
文件可以重名。先按字典序将路径排序,再过滤掉公共前缀。
其中的问题是'\'的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的更多相关文章
- 【HDOJ】4601 Letter Tree
挺有意思的一道题,思路肯定是将图转化为Trie树,这样可以求得字典序.然后,按照trie的层次求解.一直wa的原因在于将树转化为线性数据结构时要从原树遍历,从trie遍历就会wa.不同结点可能映射为t ...
- 【数据结构】B-Tree, B+Tree, B*树介绍 转
[数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...
- P3690 【模板】Link Cut Tree (动态树)
P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...
- LG3690 【模板】Link Cut Tree (动态树)
题意 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联通的 ...
- AC日记——【模板】Link Cut Tree 洛谷 P3690
[模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...
- LG3690 【模板】Link Cut Tree 和 SDOI2008 洞穴勘测
UPD:更新了写法. [模板]Link Cut Tree 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 后接两个整数(x,y),代表询问从x到y ...
- (RE) luogu P3690 【模板】Link Cut Tree
二次联通门 : luogu P3690 [模板]Link Cut Tree 莫名RE第8个点....如果有dalao帮忙查错的话万分感激 #include <cstdio> #includ ...
- LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板
P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...
- 【LeetCode】199. Binary Tree Right Side View 解题报告(Python)
[LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/probl ...
随机推荐
- ASP.NET生成日历
public string GetDayList(DateTime? date) { ; var minDate = Convert.ToDateTime(((DateTime)(date ?? Da ...
- Kafka-0.10.0.0入门
搭建环境略(伪集群即可以),但要注意Kafka的配置必须配置的,少配了也一样可以用,但是只能单机使用,外部机器无法连接,网上也有说. host.name=192.168.1.30 advertised ...
- GNU glibc
在线G-lib-c(GNU C Library库)网站 参考: 1.bitsToTypes
- C++重写与重载、重定义
文章引用自:http://blog.163.com/clevertanglei900@126/blog/static/111352259201102441934870/ 重载overload:是函数名 ...
- centos下如何用SMplayer播放WMV格式文件
安装的是centos6.6,想用来做桌面系统使用!! 装完后,其他的办公软件都安装好了.但是,视频播放却出问题了. 配置的yum安装的SMplayer播放器,播放其他的视频文件没问题,就是WMV的视频 ...
- SQL Server 2012 读写分离设置
SQL Server 2012 读写分离设置 - AlsoIn 时间 2014-07-21 17:38:00 博客园-所有随笔区 原文 http://www.cnblogs.com/also/p/ ...
- Css3 阴影效果
box-shadow:#333 0 0 5px 10px; //上下左右有阴影-webkit-box-shadow: #666 0px 5px 10px; -moz-box-shadow: #666 ...
- python正则的中文处理
因工作需要,要查找中文汉字分词,因为python正则表达式\W+表示的是所有的中文字就连标点符号都包括.所以要想办法过滤掉. 参考博客:http://log.medcl.net/item/2011/0 ...
- hdu 5429 Geometric Progression 高精度浮点数(java版本)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5429 题意:给一段长度不超过100的每个数字(可以是浮点数)的长度不超过1000的序列,问这个序列是否 ...
- CSS3 display:flex和display:box有什么区别?
**区别**,仅是各阶段草案命名.- W3C 2009年第1次草案:[display:box;](https://www.w3.org/TR/2009/WD-css3-flexbox-20090723 ...